structlog
structlog copied to clipboard
LoggerFactory frame name guessing is spoiled
Under following circumstances, name guessing from frames doesn't work:
- have structlog configured using stdlib logger and threadlocals
- create a module
scan.pywhere structlog is used to calllogger = get_logger();logger.debug(), but at the same time issues avenusian.scan() - in a module
foo.pythat venusian picks up, havelogger = get_logger()call at module level
You'll end up with a stacktrace in frame guessing from venusian call and logger in foo.py will have that logger cached. Printing foo.py:logger._logger.name confirms that.
Is that not fixable using ignore_frame_names as documented in http://www.structlog.org/en/stable/api.html#structlog.stdlib.LoggerFactory ?
No. I'd have to ignore every frame name in stack that venusian has during scanning, which could be dynamic and change with time while scan.py module is developed
Any suggestions?
I would tend to suggest to use get_logger(__name__) I guess? I’m not aware of better way to guess.
I think the best way to fix this is not to cache get_logger()._logger so aggressively. For current workaround I've used get_logger(__name__) as you said :)