]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
py/samba/logger: respect NO_COLOR env variable
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 6 Jul 2021 22:43:17 +0000 (10:43 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 6 Sep 2022 21:12:36 +0000 (21:12 +0000)
As per https://no-color.org/

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
python/samba/logger.py

index 667c6487a51a9acec883ef182611e56886025a7a..7fb2199e031bf559993618339388bc4f0502db82 100644 (file)
@@ -19,6 +19,7 @@
 import sys
 import logging
 from samba.colour import GREY, YELLOW, GREEN, RED, DARK_RED, C_NORMAL
+from samba.colour import is_colour_wanted
 
 LEVEL_COLORS = {
     logging.CRITICAL: DARK_RED,
@@ -55,8 +56,7 @@ def get_samba_logger(
                  (quiet and logging.WARNING) or logging.INFO)
 
     logger.setLevel(level)
-
-    if (hasattr(stream, 'isatty') and stream.isatty()):
+    if is_colour_wanted(stream):
         Formatter = ColoredFormatter
     else:
         Formatter = logging.Formatter