mirror of
https://github.com/frappe/bench.git
synced 2024-11-17 02:25:16 +00:00
refactor(log): use click to colour everything
A year (longer) ago, I added color to bench manually. I hadn't explored much of click back then. Had to figure out when we had to and we didnt have to colour stuff. At times the chars would just be ignored and rather printed to the terminal which was awkward...anyway, here, goodbyetoallthat :cheers: (hopefully)
This commit is contained in:
parent
20560c97c4
commit
ba289fba25
@ -22,15 +22,6 @@ folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids')
|
|||||||
sudoers_file = '/etc/sudoers.d/frappe'
|
sudoers_file = '/etc/sudoers.d/frappe'
|
||||||
|
|
||||||
|
|
||||||
class color:
|
|
||||||
nc = '\033[0m'
|
|
||||||
blue = '\033[94m'
|
|
||||||
green = '\033[92m'
|
|
||||||
yellow = '\033[93m'
|
|
||||||
red = '\033[91m'
|
|
||||||
silver = '\033[90m'
|
|
||||||
|
|
||||||
|
|
||||||
def is_bench_directory(directory=os.path.curdir):
|
def is_bench_directory(directory=os.path.curdir):
|
||||||
is_bench = True
|
is_bench = True
|
||||||
|
|
||||||
@ -43,22 +34,20 @@ def is_bench_directory(directory=os.path.curdir):
|
|||||||
|
|
||||||
def log(message, level=0):
|
def log(message, level=0):
|
||||||
levels = {
|
levels = {
|
||||||
0: color.blue + 'INFO', # normal
|
0: ("blue", "INFO"), # normal
|
||||||
1: color.green + 'SUCCESS', # success
|
1: ("green", "SUCCESS"), # success
|
||||||
2: color.red + 'ERROR', # fail
|
2: ("red", "ERROR"), # fail
|
||||||
3: color.yellow + 'WARN' # warn/suggest
|
3: ("yellow", "WARN") # warn/suggest
|
||||||
}
|
}
|
||||||
loggers = {
|
loggers = {
|
||||||
2: logger.error,
|
2: logger.error,
|
||||||
3: logger.warning
|
3: logger.warning
|
||||||
}
|
}
|
||||||
|
color, prefix = levels.get(level, levels[0])
|
||||||
start_line = (levels.get(level) + ': ') if level in levels else ''
|
|
||||||
level_logger = loggers.get(level, logger.info)
|
level_logger = loggers.get(level, logger.info)
|
||||||
end_line = '\033[0m'
|
|
||||||
|
|
||||||
level_logger(message)
|
level_logger(message)
|
||||||
print(start_line + message + end_line)
|
click.secho(f"{prefix}: {message}", fg=color)
|
||||||
|
|
||||||
|
|
||||||
def safe_decode(string, encoding = 'utf-8'):
|
def safe_decode(string, encoding = 'utf-8'):
|
||||||
|
Loading…
Reference in New Issue
Block a user