Skip to content

Commit b06bc24

Browse files
authored
Merge pull request #112 from dontnod/sho/colour-output
logging: use rich library for colour output in TTY mode
2 parents 28eed32 + 8bbaeee commit b06bc24

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

nimp/nimp_cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2014-2019 Dontnod Entertainment
2+
# Copyright © 2014–2025 Dontnod Entertainment
33

44
# Permission is hereby granted, free of charge, to any person obtaining
55
# a copy of this software and associated documentation files (the
@@ -25,6 +25,7 @@
2525
import logging
2626
import os
2727
import platform
28+
from rich.logging import RichHandler
2829
import sys
2930
import time
3031
import traceback
@@ -72,6 +73,8 @@ def main(argv=sys.argv):
7273
nimp_monitor = nimp.sys.process.Monitor()
7374
nimp_monitor.start()
7475

76+
logging.basicConfig(level=logging.INFO, format='%(message)s', datefmt='[%X]',
77+
handlers=[RichHandler()])
7578
logging.getLogger('urllib3').setLevel(logging.INFO)
7679
logging.getLogger('torf').setLevel(logging.INFO)
7780

nimp/summary.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2014-2022 Dontnod Entertainment
2+
# Copyright © 2014–2025 Dontnod Entertainment
33

44
# Permission is hereby granted, free of charge, to any person obtaining
55
# a copy of this software and associated documentation files (the
@@ -119,11 +119,12 @@ def __enter__(self):
119119

120120
root_logger = logging.root
121121

122-
# Need to do that because some log may already have been output
123-
for handler in list(logging.root.handlers):
124-
root_logger.removeHandler(handler)
125-
126-
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', level=log_level)
122+
# If stdout is not a TTY, fall back to the old log format. This is just in case there
123+
# are external tools that parse the output, we don’t want to break them.
124+
if not sys.stdout.isatty():
125+
for handler in list(logging.root.handlers):
126+
root_logger.removeHandler(handler)
127+
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', level=log_level)
127128

128129
child_processes_logger = logging.getLogger('child_processes')
129130
child_processes_logger.propagate = False

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ keywords = ["build", "compile", "unrealengine"]
2525
dynamic = ["version"]
2626

2727
dependencies = [
28+
"rich",
2829
"glob2",
2930
"packaging",
3031
"python-magic",

0 commit comments

Comments
 (0)