##// END OF EJS Templates
Add tag to log's
Juan C. Espinoza -
r1051:e0687e273615
parent child
Show More
@@ -1,4 +1,4
1 """
1 '''
2 2 SCHAINPY - LOG
3 3 Simple helper for log standarization
4 4 Usage:
@@ -13,47 +13,32 SCHAINPY - LOG
13 13 which will look like this:
14 14 [NEVER GONNA] - give you up
15 15 with color red as background and white as foreground.
16 """
17 import os
18 import sys
16 '''
17
19 18 import click
20 19
21 def warning(message):
22 click.echo(click.style('[WARNING] - ' + message, fg='yellow'))
20 def warning(message, tag='Warning'):
21 click.echo(click.style('[{}] {}'.format(tag, message), fg='yellow'))
22 pass
23
23 24
25 def error(message, tag='Error'):
26 click.echo(click.style('[{}] {}'.format(tag, message), fg='red'))
27 pass
24 28
25 def error(message):
26 click.echo(click.style('[ERROR] - ' + message, fg='red', bg='black'))
27 29
30 def success(message, tag='Info'):
31 click.echo(click.style('[{}] {}'.format(tag, message), fg='green'))
32 pass
28 33
29 def success(message):
30 click.echo(click.style(message, fg='green'))
31 34
35 def log(message, tag='Info'):
36 click.echo('[{}] {}'.format(tag, message))
37 pass
32 38
33 def log(message, topic='LOG'):
34 click.echo('[{}] - {}'.format(topic, message))
35 39
36 def makelogger(topic, bg='reset', fg='reset'):
40 def makelogger(tag, bg='reset', fg='reset'):
37 41 def func(message):
38 click.echo(click.style('[{}] - '.format(topic.upper()) + message,
42 click.echo(click.style('[{}] {}'.format(tag.upper(), message),
39 43 bg=bg, fg=fg))
40 44 return func
41
42 class LoggerForFile():
43 def __init__(self, filename):
44 self.old_stdout=sys.stdout
45 cwd = os.getcwd()
46 self.log_file = open(os.path.join(cwd, filename), 'w+')
47 def write(self, text):
48 text = text.rstrip()
49 if not text:
50 return
51 self.log_file.write(text + '\n')
52 self.old_stdout.write(text + '\n')
53 def flush(self):
54 self.old_stdout.flush()
55
56 def logToFile(filename='log.log'):
57 logger = LoggerForFile(filename)
58 sys.stdout = logger
59
General Comments 0
You need to be logged in to leave comments. Login now