mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-28 16:28:33 +03:00
pysim/log: also accept ANSI strings to specify the log message colors
the PySimLogger class currently only accepts cmd2 color enum values. This is what we need for pySim-shell.py. However, in case we want to use the PySimLogger in stand-alone programs that do not use cmd2, this is a bit bulky. Let's add some flexibility to PySimLogger, so that we can specify the colors as raw ANSI strings as well. Change-Id: I93543e19649064043ae8323f82ecd8c423d1d921 Related: SYS#7725
This commit is contained in:
@@ -108,7 +108,10 @@ class PySimLogger:
|
|||||||
formatted_message = logging.Formatter.format(PySimLogger.__formatter, record)
|
formatted_message = logging.Formatter.format(PySimLogger.__formatter, record)
|
||||||
color = PySimLogger.colors.get(record.levelno)
|
color = PySimLogger.colors.get(record.levelno)
|
||||||
if color:
|
if color:
|
||||||
PySimLogger.print_callback(style(formatted_message, fg = color))
|
if type(color) is str:
|
||||||
|
PySimLogger.print_callback(color + formatted_message + "\033[0m")
|
||||||
|
else:
|
||||||
|
PySimLogger.print_callback(style(formatted_message, fg = color))
|
||||||
else:
|
else:
|
||||||
PySimLogger.print_callback(formatted_message)
|
PySimLogger.print_callback(formatted_message)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user