def enable_pretty_logging():
"""Turns on formatted logging output as configured."""
if (options.log_to_stderr or
(options.log_to_stderr is None and not options.log_file_prefix)):
# Set up color if we are in a tty and curses is installed
color = False
if curses and sys.stderr.isatty():
try:
curses.setupterm()
if curses.tigetnum("colors") > 0:
color = True
except:
pass
channel = logging.StreamHandler()
channel.setFormatter(_LogFormatter(color=color))
logging.getLogger().addHandler(channel)
if options.log_file_prefix:
channel = logging.handlers.RotatingFileHandler(
filename=options.log_file_prefix,
maxBytes=options.log_file_max_size,
backupCount=options.log_file_num_backups)
channel.setFormatter(_LogFormatter(color=False))
logging.getLogger().addHandler(channel)
评论列表
文章目录