Skip to content

Commit 751f2e3

Browse files
committed
replace common warning and error prefixes with emojis
1 parent 03a4f2c commit 751f2e3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

xpra/log.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
LOG_PREFIX = os.environ.get("XPRA_LOG_PREFIX", LOG_PREFIX)
2525
DEBUG_MODULES = tuple(x.strip() for x in os.environ.get("XPRA_DEBUG_MODULES", "").split(",") if x.strip())
2626
NOPREFIX_FORMAT: Final[str] = "%(message)s"
27+
EMOJIS = os.environ.get("XPRA_EMOJIS", "1") == "1"
2728

2829

2930
BACKTRACE_LEVEL = int(os.environ.get("XPRA_LOG_BACKTRACE_LEVEL", logging.CRITICAL))
@@ -38,6 +39,7 @@
3839
debug_enabled_categories: set[str] = set()
3940
debug_disabled_categories: set[str] = set()
4041
backtrace_expressions: set[re.Pattern] = set()
42+
emojis = False
4143

4244

4345
MODULE_FILE = os.path.join(os.sep, "xpra", "log.py") # ie: "/xpra/log.py"
@@ -171,6 +173,9 @@ def enable_color(to=sys.stdout, format_string=NOPREFIX_FORMAT) -> None:
171173
csh = ColorStreamHandler(to)
172174
csh.setFormatter(logging.Formatter(format_string))
173175
setloghandler(csh)
176+
if EMOJIS:
177+
global emojis
178+
emojis = True
174179

175180

176181
def enable_format(format_string: str) -> None:
@@ -544,9 +549,19 @@ def info(self, msg: str, *args, **kwargs) -> None:
544549
self.log(logging.INFO, msg, *args, **kwargs)
545550

546551
def warn(self, msg: str, *args, **kwargs) -> None:
552+
if emojis:
553+
if msg.startswith("Warning:"):
554+
msg = "⚠️ " + msg[len("Warning:"):].strip()
555+
elif msg.startswith(" "):
556+
msg = " " + msg.strip()
547557
self.log(logging.WARN, msg, *args, **kwargs)
548558

549559
def error(self, msg: str, *args, **kwargs) -> None:
560+
if emojis:
561+
if msg.startswith("Error:"):
562+
msg = "🔴 " + msg[len("Error:"):].strip()
563+
elif msg.startswith(" "):
564+
msg = " " + msg.strip()
550565
self.log(logging.ERROR, msg, *args, **kwargs)
551566

552567
def estr(self, e, **kwargs) -> None:

0 commit comments

Comments
 (0)