You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just diving into structlog (using the latest version, 23.1.0). I'm adding structlog to an existing codebase. I looked around the issue tracker if this was already reported but I didn't find anything other than #506.
We have a lot of existing log statements that I was hoping would be an easy switch as a drop-in replacements by switching logging.getLogger with structlog.get_logger. However, I'm running into a compatibility issue with logger.exception statements like this:
logger.exception("Error when copying %s", url)
These statements fail with this error:
TypeError: exception() takes 2 positional arguments but 3 were given
Only logger.exception behaves differently.
Here's a minimal reproducible example I pulled from our structlog integration that generates the error:
importloggingimportorjsonimportstructlogfromstructlog.contextvarsimportmerge_contextvarsstructlog.configure(
cache_logger_on_first_use=True,
wrapper_class=structlog.make_filtering_bound_logger(logging.INFO),
processors=[
merge_contextvars,
structlog.stdlib.ExtraAdder(),
structlog.processors.add_log_level,
structlog.processors.format_exc_info,
structlog.processors.TimeStamper(fmt="iso", utc=True),
structlog.processors.StackInfoRenderer(),
structlog.processors.JSONRenderer(serializer=orjson.dumps),
],
logger_factory=structlog.BytesLoggerFactory(),
)
structlog_logger=structlog.get_logger()
stdlib_logger=logging.getLogger()
deflog_exception(logger):
try:
raiseException("This is a test exception")
exceptException:
logger.exception("This is a test exception %d", 1)
log_exception(stdlib_logger)
log_exception(structlog_logger)
The first logger.exception, using stdlib logger works as expected (without failing). The second log statement with structlog fails with an exception.
It's a couple of dozen places in our code where we have logger.exception with arguments and it won't be a huge effort to refactor for me, however, I'm curious if I'm missing something obvious here.
What should be the behaviour here? If this is the expected behaviour, what's the recommended approach here?
The text was updated successfully, but these errors were encountered:
Hi,
I'm just diving into structlog (using the latest version, 23.1.0). I'm adding structlog to an existing codebase. I looked around the issue tracker if this was already reported but I didn't find anything other than #506.
We have a lot of existing log statements that I was hoping would be an easy switch as a drop-in replacements by switching
logging.getLogger
withstructlog.get_logger
. However, I'm running into a compatibility issue withlogger.exception
statements like this:These statements fail with this error:
Only
logger.exception
behaves differently.Here's a minimal reproducible example I pulled from our structlog integration that generates the error:
The first logger.exception, using stdlib logger works as expected (without failing). The second log statement with structlog fails with an exception.
It's a couple of dozen places in our code where we have
logger.exception
with arguments and it won't be a huge effort to refactor for me, however, I'm curious if I'm missing something obvious here.What should be the behaviour here? If this is the expected behaviour, what's the recommended approach here?
The text was updated successfully, but these errors were encountered: