Roger Binns
Roger Binns

Reputation: 3348

Cython logging filename & module

If you call the logging module from cythonised code including funcName and module then you get wrong values for those attributes. Instead you get the values from the first higher level caller that wasn't from cython, which is extremely misleading. The reason is that cython doesn't generate call frames, so they are invisible to the logging.findCaller method.

Is there a way to make logging work with cython?

I do not wish to change every location that calls logging. I'm happy to monkeypatch logging.findCaller if there is an alternate way of finding the information.

Upvotes: 6

Views: 2153

Answers (1)

Roger Binns
Roger Binns

Reputation: 3348

The short term answer is that cython doesn't add stack frames and doesn't have configuration to do so (except for exceptions, after the fact as the stack is unwound). Developers on the mailing list are considering adding them as an option, with logging being another example of why they are needed.

A short term workaround is to adjust the code (programmatically) during compilation to stash frame information (method name, module, line number etc) into thread local variables, and monkey patch logging.findCaller to get those details that way if available.

Upvotes: 4

Related Questions