Fix utils.log so it works with sys.stderr == None
This commit is contained in:
parent
a254b4c001
commit
1ed70bfef7
@ -89,6 +89,7 @@ def init_log(args):
|
|||||||
if args.logfilter is not None and numeric_level <= logging.DEBUG:
|
if args.logfilter is not None and numeric_level <= logging.DEBUG:
|
||||||
console.addFilter(LogFilter(args.logfilter.split(',')))
|
console.addFilter(LogFilter(args.logfilter.split(',')))
|
||||||
root = getLogger()
|
root = getLogger()
|
||||||
|
if console is not None:
|
||||||
root.addHandler(console)
|
root.addHandler(console)
|
||||||
root.addHandler(ram)
|
root.addHandler(ram)
|
||||||
root.setLevel(logging.NOTSET)
|
root.setLevel(logging.NOTSET)
|
||||||
@ -107,6 +108,9 @@ def _init_handlers(level, color):
|
|||||||
console_formatter, ram_formatter, use_colorama = _init_formatters(
|
console_formatter, ram_formatter, use_colorama = _init_formatters(
|
||||||
level, color)
|
level, color)
|
||||||
|
|
||||||
|
if sys.stderr is None:
|
||||||
|
console_handler = None
|
||||||
|
else:
|
||||||
if use_colorama:
|
if use_colorama:
|
||||||
stream = colorama.AnsiToWin32(sys.stderr)
|
stream = colorama.AnsiToWin32(sys.stderr)
|
||||||
else:
|
else:
|
||||||
@ -140,6 +144,9 @@ def _init_formatters(level, color):
|
|||||||
else:
|
else:
|
||||||
console_fmt = SIMPLE_FMT
|
console_fmt = SIMPLE_FMT
|
||||||
console_fmt_colored = SIMPLE_FMT_COLORED
|
console_fmt_colored = SIMPLE_FMT_COLORED
|
||||||
|
ram_formatter = logging.Formatter(EXTENDED_FMT, DATEFMT, '{')
|
||||||
|
if sys.stderr is None:
|
||||||
|
return None, ram_formatter, False
|
||||||
use_colorama = False
|
use_colorama = False
|
||||||
if (ColoredFormatter is not None and (os.name == 'posix' or colorama) and
|
if (ColoredFormatter is not None and (os.name == 'posix' or colorama) and
|
||||||
sys.stderr.isatty() and color):
|
sys.stderr.isatty() and color):
|
||||||
@ -157,7 +164,6 @@ def _init_formatters(level, color):
|
|||||||
use_colorama = True
|
use_colorama = True
|
||||||
else:
|
else:
|
||||||
console_formatter = logging.Formatter(console_fmt, DATEFMT, '{')
|
console_formatter = logging.Formatter(console_fmt, DATEFMT, '{')
|
||||||
ram_formatter = logging.Formatter(EXTENDED_FMT, DATEFMT, '{')
|
|
||||||
return console_formatter, ram_formatter, use_colorama
|
return console_formatter, ram_formatter, use_colorama
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user