Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "ValueError" using Loguru with Cython (when missing stack frame) #1240

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

Delgan
Copy link
Owner

@Delgan Delgan commented Nov 26, 2024

Fix #88.
Fix #680.

In Cython, calling logger.info() used to cause a ValueError("call stack is not deep enough") which happens because of Cython optimizations.

As a workaround, this PR wraps the call into a try / except clause and generate "dummy" information if the frame failed to be retrieve:

  • module name -> None
  • file name -> "<unknown>"
  • function name -> "<unknown>"
  • line no -> 0

Not ideal, but certainly better than if Loguru didn't work at all.

Example of output:

2024-11-26 15:58:48.985 | INFO | None:<unknown>:0 - Message from Cython!

@Delgan Delgan merged commit ab33cc0 into master Nov 26, 2024
21 checks passed
@Delgan Delgan deleted the fix-cython branch November 26, 2024 16:36
@namoshizun
Copy link

This is awesome!! We've been stuck on the "depth=-1' workaround for quite some time. All of our code has to be compiled using Cython due to proprietary requirements. Can we expect a new release that contains this fix soon 😉 ?

@Delgan
Copy link
Owner Author

Delgan commented Nov 27, 2024

@namoshizun Probably before the end of the week if all goes well. 👍

You can also test it in advance (and report me any bug) by installing loguru from the repo directly:

pip install git+https://github.com/delgan/loguru@ab33cc0101129721cd024b8a63c4059cbc8844d1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants