Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I'm having an issue when I use structlog to emit errors:
try: raise ValueError except Exception: structlog.get_logger().exception("something happened")
That will remove the
This is my configuration:
json_handler = logging.StreamHandler(sys.stdout) json_handler.setFormatter(jsonlogger.JsonFormatter()) logging.basicConfig( format="%(message)s", handlers=[json_handler], level=logging.INFO, ) 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=structlog.threadlocal.wrap_dict(dict), logger_factory=structlog.stdlib.LoggerFactory(), wrapper_class=structlog.stdlib.BoundLogger, cache_logger_on_first_use=True, )
I ran into the same issue and it can be reproduced with the default logger:
import structlog logger = structlog.get_logger() try: 1/0 except: logger.exception("Does not print the exception") logger.exception("Prints the exception", exc_info=True)
The corresponding output with structlog
I think the issue is here:
Pure structlog / print logger just assumes
So structlog is not exactly a drop-in replacement for stdlib when used within an except block.
Perhaps we could find a way that usage of the exception method will also inject
btw, I think this is again #130 (which was closed).
@wimglenn You too are in the wrong ticket and the class you're referring to is the wrong end: it's the one that only writes out the result. The interesting one is the generic BoundLogger which is the interface to the user.
I'm closing this because the original problem is solved by my first response to Danny.
This problem keeps coming up but as I've explained in #130, I cannot change the behavior of the default BoundLogger lest I want to break thousands of systems. But I do agree that it is unfortunate, that