3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-04-07 06:44:06 +00:00

Add colors to early and late log messages

Signed-off-by: Claire Xenia Wolf <claire@clairexen.net>
This commit is contained in:
Claire Xenia Wolf 2022-11-02 12:35:11 +01:00
parent 003ccf7197
commit e8d713cc27
2 changed files with 16 additions and 17 deletions

View file

@ -19,9 +19,9 @@
import argparse, json, os, sys, shutil, tempfile, re
##yosys-sys-path##
from sby_core import SbyConfig, SbyTask, SbyAbort, SbyTaskloop, process_filename
from sby_core import SbyConfig, SbyTask, SbyAbort, SbyTaskloop, process_filename, dress_message
from sby_jobserver import SbyJobClient, process_jobserver_environment
import time, platform
import time, platform, click
process_jobserver_environment() # needs to be called early
@ -177,9 +177,8 @@ prep -top top
early_logmsgs = list()
def early_log(workdir, msg):
tm = time.localtime()
early_logmsgs.append("SBY {:2d}:{:02d}:{:02d} [{}] {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, workdir, msg))
print(early_logmsgs[-1])
early_logmsgs.append(dress_message(workdir, msg))
click.echo(early_logmsgs[-1])
def read_sbyconfig(sbydata, taskname):
cfgdata = list()
@ -567,7 +566,6 @@ else:
failed.append(taskname)
if failed and (len(tasknames) > 1 or tasknames[0] is not None):
tm = time.localtime()
print("SBY {:2d}:{:02d}:{:02d} The following tasks failed: {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, failed))
click.echo(dress_message(None, click.style(f"The following tasks failed: {failed}", fg="red", bold=True)))
sys.exit(retcode)

View file

@ -46,6 +46,16 @@ def process_filename(filename):
return filename
def dress_message(workdir, logmessage):
tm = localtime()
if workdir is not None:
logmessage = "[" + click.style(workdir, fg="blue") + "] " + logmessage
return " ".join([
click.style("SBY", fg="blue"),
click.style("{:2d}:{:02d}:{:02d}".format(tm.tm_hour, tm.tm_min, tm.tm_sec), fg="green"),
logmessage
])
class SbyProc:
def __init__(self, task, info, deps, cmdline, logfile=None, logstderr=True, silent=False):
self.running = False
@ -680,18 +690,9 @@ class SbyTask(SbyConfig):
self.procs_pending.remove(proc)
self.taskloop.procs_pending.remove(proc)
def dress_message(self, logmessage):
tm = localtime()
return " ".join([
click.style("SBY", fg="blue"),
click.style("{:2d}:{:02d}:{:02d}".format(tm.tm_hour, tm.tm_min, tm.tm_sec), fg="green"),
"[" + click.style(self.workdir, fg="blue") + "]",
logmessage
])
def log(self, logmessage):
tm = localtime()
line = self.dress_message(logmessage)
line = dress_message(self.workdir, logmessage)
for target in self.log_targets:
click.echo(line, file=target)