def setup(self, tree=None) -> None: if tree is None: tree = logging_tree.tree() if self.level_by_logger.get("logging_tree", "info").upper() == "DEBUG": logging_tree.printout() for n, l in self.level_by_logger.items(): if n == tree[0]: print( f"\033[33m setting logger \"{n}\" ({tree[1]}) at level {l}\033[0m" ) tree[1].setLevel(l.upper()) for child in tree[2]: self.setup(child)
def configure_logging(debug=False, syslog=False, silenced_loggers=None, level_overrides=None): if silenced_loggers is None: silenced_loggers = [] if level_overrides is None: level_overrides = {} level = 'DEBUG' if debug else 'INFO' renderers = [ dev.ConsoleRenderer(), ] if debug else [ logstash_processor, processors.JSONRenderer(separators=(',', ':')), add_syslog_program(syslog), ] structlog_processors = [ stdlib.filter_by_level, stdlib.add_logger_name, stdlib.add_log_level, fix_logger_name, format_request, ensure_event, stdlib.PositionalArgumentsFormatter(), processors.TimeStamper(fmt="ISO", key='@timestamp'), processors.StackInfoRenderer(), processors.format_exc_info, ] + renderers configure( processors=structlog_processors, context_class=dict, logger_factory=stdlib.LoggerFactory(), wrapper_class=stdlib.BoundLogger, cache_logger_on_first_use=True, ) structlog = {'handlers': ['raw'], 'level': level, 'propagate': False} null = {'handlers': ['null'], 'propagate': False} loggers = {l: root(level_overrides.get(l, level)) for l, _, _ in logging_tree.tree()[2]} loggers['feedhq'] = structlog for nulled_logger in silenced_loggers: loggers[nulled_logger] = null raw = { 'level': level, 'class': 'logging.handlers.SysLogHandler', 'address': '/dev/log', 'facility': 'local0', } if syslog else { 'level': level, 'class': 'logging.StreamHandler', } return { 'version': 1, 'level': level, 'handlers': { 'root': { 'level': level, '()': StructlogHandler, }, 'raw': raw, 'null': { 'class': 'logging.NullHandler', }, }, 'loggers': loggers, 'root': root(level), }
def get_root_mail_handler_email(): for handler in tree()[1].handlers: if isinstance(handler, SMTPHandler): return handler.toaddrs return None
def get_root_handlers_names(): return [x.name for x in tree()[1].handlers]
def teardown_config(): logging.getLogger('tests.test_color_bucket_logger').handlers = [] lt = logging_tree.tree() delete_log_tree(lt) logging.config.dictConfig(min_log_config)
def configure_logging(debug=False, syslog=False, silenced_loggers=None, level_overrides=None): if silenced_loggers is None: silenced_loggers = [] if level_overrides is None: level_overrides = {} level = 'DEBUG' if debug else 'INFO' renderers = [ dev.ConsoleRenderer(), ] if debug else [ logstash_processor, processors.JSONRenderer(separators=(',', ':')), add_syslog_program(syslog), ] structlog_processors = [ stdlib.filter_by_level, stdlib.add_logger_name, stdlib.add_log_level, fix_logger_name, format_request, ensure_event, stdlib.PositionalArgumentsFormatter(), processors.TimeStamper(fmt="ISO", key='@timestamp'), processors.StackInfoRenderer(), processors.format_exc_info, ] + renderers configure( processors=structlog_processors, context_class=dict, logger_factory=stdlib.LoggerFactory(), wrapper_class=stdlib.BoundLogger, cache_logger_on_first_use=True, ) structlog = {'handlers': ['raw'], 'level': level, 'propagate': False} null = {'handlers': ['null'], 'propagate': False} loggers = { l: root(level_overrides.get(l, level)) for l, _, _ in logging_tree.tree()[2] } loggers['feedhq'] = structlog for nulled_logger in silenced_loggers: loggers[nulled_logger] = null raw = { 'level': level, 'class': 'logging.handlers.SysLogHandler', 'address': '/dev/log', 'facility': 'local0', } if syslog else { 'level': level, 'class': 'logging.StreamHandler', } return { 'version': 1, 'level': level, 'handlers': { 'root': { 'level': level, '()': StructlogHandler, }, 'raw': raw, 'null': { 'class': 'logging.NullHandler', }, }, 'loggers': loggers, 'root': root(level), }