structlog icon indicating copy to clipboard operation
structlog copied to clipboard

LoggerFactory frame name guessing is spoiled

Open domenkozar opened this issue 10 years ago • 4 comments

Under following circumstances, name guessing from frames doesn't work:

  • have structlog configured using stdlib logger and threadlocals
  • create a module scan.py where structlog is used to call logger = get_logger();logger.debug(), but at the same time issues a venusian.scan()
  • in a module foo.py that venusian picks up, have logger = 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.

domenkozar avatar Aug 14 '15 12:08 domenkozar

Is that not fixable using ignore_frame_names as documented in http://www.structlog.org/en/stable/api.html#structlog.stdlib.LoggerFactory ?

hynek avatar Aug 14 '15 13:08 hynek

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

domenkozar avatar Aug 14 '15 13:08 domenkozar

Any suggestions?

I would tend to suggest to use get_logger(__name__) I guess? I’m not aware of better way to guess.

hynek avatar Aug 14 '15 14:08 hynek

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 :)

domenkozar avatar Aug 14 '15 14:08 domenkozar