mirror of
https://github.com/samba-team/samba.git
synced 2025-12-17 04:23:50 +03:00
logger: use color automatically for a tty
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Wed Nov 21 10:46:20 CET 2018 on sn-devel-144
This commit is contained in:
@@ -39,7 +39,7 @@ class ColoredFormatter(logging.Formatter):
|
||||
|
||||
|
||||
def get_samba_logger(
|
||||
name='samba', stream=sys.stderr, use_color=True,
|
||||
name='samba', stream=sys.stderr,
|
||||
level=None, verbose=False, quiet=False,
|
||||
fmt=('%(levelname)s %(asctime)s pid:%(process)d '
|
||||
'%(pathname)s #%(lineno)d: %(message)s'),
|
||||
@@ -56,7 +56,10 @@ def get_samba_logger(
|
||||
|
||||
logger.setLevel(level)
|
||||
|
||||
Formatter = use_color and ColoredFormatter or logging.Formatter
|
||||
if (hasattr(stream, 'isatty') and stream.isatty()):
|
||||
Formatter = ColoredFormatter
|
||||
else:
|
||||
Formatter = logging.Formatter
|
||||
formatter = Formatter(fmt=fmt, datefmt=datefmt)
|
||||
|
||||
handler = logging.StreamHandler(stream=stream)
|
||||
|
||||
Reference in New Issue
Block a user