mirror of
https://github.com/frappe/bench.git
synced 2024-11-13 16:56:33 +00:00
refactor: bench.utils.log
Maintain `bench.LOG_BUFFER` for entire process when `bench.cli.fancy` is set
This commit is contained in:
parent
747be65f92
commit
ac07d8dc52
@ -30,6 +30,7 @@ from bench.utils import (
|
||||
from bench.utils.bench import get_env_cmd
|
||||
|
||||
from_command_line = False
|
||||
bench.LOG_BUFFER = []
|
||||
change_uid_msg = "You should not run this command as root"
|
||||
src = os.path.dirname(__file__)
|
||||
|
||||
|
@ -48,19 +48,32 @@ def is_frappe_app(directory: str) -> bool:
|
||||
return bool(is_frappe_app)
|
||||
|
||||
|
||||
def log(message, level=0):
|
||||
def log(message, level=0, no_log=False):
|
||||
import bench
|
||||
import bench.cli
|
||||
|
||||
levels = {
|
||||
0: ("blue", "INFO"), # normal
|
||||
1: ("green", "SUCCESS"), # success
|
||||
2: ("red", "ERROR"), # fail
|
||||
3: ("yellow", "WARN"), # warn/suggest
|
||||
}
|
||||
loggers = {2: logger.error, 3: logger.warning}
|
||||
color, prefix = levels.get(level, levels[0])
|
||||
level_logger = loggers.get(level, logger.info)
|
||||
|
||||
level_logger(message)
|
||||
click.secho(f"{prefix}: {message}", fg=color)
|
||||
color, prefix = levels.get(level, levels[0])
|
||||
|
||||
if bench.cli.from_command_line and bench.cli.fancy:
|
||||
bench.LOG_BUFFER.append(
|
||||
{"prefix": prefix, "message": message, "color": color,}
|
||||
)
|
||||
|
||||
if no_log:
|
||||
click.secho(message, fg=color)
|
||||
else:
|
||||
loggers = {2: logger.error, 3: logger.warning}
|
||||
level_logger = loggers.get(level, logger.info)
|
||||
|
||||
level_logger(message)
|
||||
click.secho(f"{prefix}: {message}", fg=color)
|
||||
|
||||
|
||||
def check_latest_version():
|
||||
|
Loading…
Reference in New Issue
Block a user