Skip to content

Commit

Permalink
Add documentation about Cython limitations (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Jun 11, 2019
1 parent 6b277f8 commit 002076f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/resources/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Code snippets and recipes for ``loguru``
.. |level| replace:: :meth:`~loguru._logger.Logger.level()`
.. |configure| replace:: :meth:`~loguru._logger.Logger.configure()`

.. _`GH#88`: https://github.com/Delgan/loguru/issues/88

Changing the level of an existing handler
-----------------------------------------
Expand Down Expand Up @@ -289,3 +290,20 @@ You may also capture warnings emitted by your application by replacing |warnings
showwarning_(message, *args, **kwargs)

warnings.showwarning = showwarning


Using Loguru's ``logger`` within a Cython module
------------------------------------------------

Loguru and Cython do not interoperate very well. This is because Loguru (and logging generally) heavily relies on Python stack frames while Cython, being an alternative Python implementation, try to get ride of these frames for optimisation reasons.

Calling the ``logger`` from code compiled with Cython may raise this kind of exception::

ValueError: call stack is not deep enough

This error happens when Loguru tries to access a stack frame which has been suppressed by Cython. There is no way for Loguru to retrieve contextual information of the logged message, but there exists a workaround that will at least prevent your application to crash::

# Add this at the start of your file
logger = logger.opt(depth=-1)

Note that logged messages should be displayed correctly, but function name and other information will be incorrect. This issue is discussed in `GH#88`_.

0 comments on commit 002076f

Please sign in to comment.