我正在使用 python 自定义日志 - TRACE 是下面代码中的自定义日志级别。
使用默认记录器,它工作正常
但是当我将它更改为 structlog 时,它给出了错误。
structlog 无法识别以下代码中的 TRACE。
似乎 structlog 不支持自定义日志级别?
已经尝试过提到的解决方法https://github.com/hynek/structlog/issues/47
IE
structlog.stdlib.TRACE = TRACE = 5
structlog.stdlib._NAME_TO_LEVEL['trace'] = TRACE
但它不工作
TRACE = 19
logging.addLevelName(TRACE, "TRACE")
logging.basicConfig(
level=os.environ.get("LOGLEVEL", "TRACE"),
format=os.environ.get("LOGFORMAT", '%(levelname)-8s= %(asctime)-15s = %(message)s'))
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.stdlib.render_to_log_kwargs,
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
#LOG = logging.getLogger() ->> Working fine
LOG = structlog.getLogger()
LOG.log(TRACE, "hello") ->> error on this line
LOG.info("testing")