@logger.catch to log file?
See original GitHub issueI had a look through other issues and couldn’t find anything relevant so here goes.
Can I intercept an unhandled exception in my function so that the printed traceback gets also put into my sink file? I tried with both @logger.catch()
and @logger.catch(reraise=True)
, both to no avail.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Logger - loguru documentation - Read the Docs
When a message is logged, a “record” is associated with it. This record is a dict which contains information about the logging context:...
Read more >How to get file the Python logging module is currently logging ...
For my basic usage of a single file log, this worked logging.getLoggerClass().root.handlers[0].baseFilename.
Read more >Logging Exceptions in Java - Loggly
In our program, we have a class that opens a file, writes to it, and then closes it. In this class, we catch...
Read more >Exception Logging to Text file - C# Corner
In this article we will learn about the Exception Logging to Text file using asp.net C#.
Read more >How to log a Python exception? - GeeksforGeeks
Logging an exception in python with an error can be done in the logging.exception() method. This function logs a message with level ERROR...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Exceptions occurring inside a function decorated with
@logger.catch
should be logged to your sinks.Basically,
logger.catch()
is a s simple wrapper around your code which does the following:You may need to wrap your entire application of you want to catch any exception occurring anywhere, for example (
logger.catch()
can be used as a context manager too):The stack trace should be written to your file as long as the exception is caught by Loguru, or that you manually log it using
logger.exception("Some message")
in theexcept
block of exception handling.@mowarsadsa The
test
function does not seem decorated withlogger.catch()
so the raisedException
can’t be captured by Loguru.