hynek / structlog

Simple, powerful, and fast logging for Python.
https://www.structlog.org/
Other
3.48k stars 220 forks source link

CallSite Parameters first exception call stack #652

Open Forceres opened 3 weeks ago

Forceres commented 3 weeks ago

Is it possible to retain callsite params if exception is handled on higher level like general exception handler? Tried to override it manually, but it doesn't work.

def general_exception_handler(error: Exception):
    traceback_exception = TracebackException.from_exception(exc)
    filename = traceback_exception.stack[-1].filename
    lineno = traceback_exception.stack[-1].lineno
    func_name = traceback_exception.stack[-1].name
    module = (traceback_exception.stack[-1].filename.removeprefix(getcwd()).lstrip(os.sep).
              replace('.py', '').replace(os.sep, '.'))
    logger: LoggerProtocol = get_logger(module)
    logger.error(detail, extra=extra, lineno=lineno, func_name='test')