##// END OF EJS Templates
Merge with px1000 branch
Merge with px1000 branch

File last commit:

r1134:d5610a11112f
r1164:80b8ab8c0c11 merge
Show More
log.py
57 lines | 1.7 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Add tag to log's
r1051 '''
José Chávez
added log helper
r943 SCHAINPY - LOG
Simple helper for log standarization
Usage:
from schainpy.utils import log
log.error('A kitten died beacuse of you')
log.warning('You are doing it wrong but what the heck, I'll allow it)
log.succes('YOU ROCK!')
To create your own logger inside your class do it like this:
from schainpy.utils import log
awesomeLogger = log.makelogger("never gonna", bg="red", fg="white")
awesomeLogger('give you up')
which will look like this:
[NEVER GONNA] - give you up
with color red as background and white as foreground.
Juan C. Espinoza
Add tag to log's
r1051 '''
José Chávez
added log helper
r943 import click
José Chávez
formatting
r1084
Improve logger
r1134 def warning(message, tag='Warning', nl=True):
if tag:
click.echo(click.style('[{}] {}'.format(tag, message), fg='yellow'), nl=nl)
else:
click.echo(click.style('{}'.format(message), fg='yellow'), nl=nl)
Juan C. Espinoza
Add tag to log's
r1051 pass
José Chávez
added log helper
r943
Improve logger
r1134 def error(message, tag='Error', nl=True):
if tag:
click.echo(click.style('[{}] {}'.format(tag, message), fg='red'), nl=nl)
else:
click.echo(click.style('{}'.format(message), fg='red'), nl=nl)
Juan C. Espinoza
Add tag to log's
r1051 pass
José Chávez
added log helper
r943
Improve logger
r1134 def success(message, tag='Success', nl=True):
if tag:
click.echo(click.style('[{}] {}'.format(tag, message), fg='green'), nl=nl)
else:
click.echo(click.style('{}'.format(message), fg='green'), nl=nl)
Juan C. Espinoza
Add tag to log's
r1051 pass
José Chávez
added log helper
r943
Improve logger
r1134 def log(message, tag='Info', nl=True):
if tag:
click.echo('[{}] {}'.format(tag, message), nl=nl)
else:
click.echo('{}'.format(message), nl=nl)
Juan C. Espinoza
Add tag to log's
r1051 pass
José Chávez
added log helper
r943
Juan C. Espinoza
Add tag to log's
r1051 def makelogger(tag, bg='reset', fg='reset'):
José Chávez
added log helper
r943 def func(message):
José Chávez
formatting
r1084 click.echo(click.style('[{}] {}'.format(
tag.upper(), message), bg=bg, fg=fg))
José Chávez
added log helper
r943 return func