def parse_logger_callback(self): if options.disable_log: options.logging = None if options.log_file_prefix and options.log_port_prefix: options.log_file_prefix += ".%s" % options.port if options.log_patch: logging.handlers.TimedRotatingFileHandler = ProcessLogTimedFileHandler tornado_logger = logging.getLogger('tornado') enable_pretty_logging(logger=tornado_logger) logdir = options.logging_dir or settings.LOGGING_DIR for log in settings.LOGGING: opt = OptionParser() define_logging_options(opt) self.define(opt) opt.log_rotate_when = log.get('when', 'midnight') opt.log_to_stderr = log.get('log_to_stderr', False) opt.logging = log.get('level', 'INFO') opt.log_file_prefix = os.path.join(logdir, log['filename']) if log.get('backups'): opt.log_file_num_backups = log.get('backups') if opt.log_port_prefix: opt.log_file_prefix += ".%s" % options.port opt.log_rotate_interval = log.get('interval', 1) opt.log_rotate_mode = 'time' logger = logging.getLogger(log['name']) if not settings.DEBUG: logger.propagate = 0 else: if not opt.log_to_stderr: logger.propagate = 0 else: logger.propagate = 1 enable_pretty_logging(options=opt, logger=logger) map(lambda h: h.setFormatter(LogFormatter(fmt=log.get("formatter", LogFormatter.DEFAULT_FORMAT), color=settings.DEBUG)), logger.handlers)
""" return options.parse_command_line(args, final=final) def parse_config_file(path, final=True): """Parses global options from a config file. See `OptionParser.parse_config_file`. """ return options.parse_config_file(path, final=final) def print_help(file=None): """Prints all the command line options to stderr (or another file). See `OptionParser.print_help`. """ return options.print_help(file) def add_parse_callback(callback): """Adds a parse callback, to be invoked when option parsing is done. See `OptionParser.add_parse_callback` """ options.add_parse_callback(callback) # Default options define_logging_options(options)
def setUp(self): super(EnablePrettyLoggingTest, self).setUp() self.options = OptionParser() define_logging_options(self.options) self.logger = logging.Logger('tornado.test.log_test.EnablePrettyLoggingTest') self.logger.propagate = False