question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

backtrace=False, but loguru is still showing tracebacks on exceptions

See original GitHub issue

logger.add("/var/log/protectwise_bootstrap.log", backtrace=False, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}")

backtrace=False, but loguru is still showing tracebacks on exceptions

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Delgancommented, Jun 2, 2019

Hi.

I guess you have two configured handlers: the first one logs messages to sys.stderr (this is the default handler automatically added), the second one logs messages to "protectwise_bootstrap.log" (the handler you manually added).

The backtrace properties of handlers are independent of each others. The default handler use backtrace=True. So, even if you add a new handler with logger.add(..., backtrace=False), the default one is not modified and will display full traceback.

You can either set LOGURU_BACKTRACE=NO for development, or explicitly add a sys.stderr handler with backtrace=False:

logger.remove()  # Remove default handler (and all others)
logger.add(sys.stderr, backtrace=False)
logger.add("protectwise_bootstrap.log", backtrace=False, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}")

Alternatively, using configure():

# Default handler (and all others) is automatically removed while using '.configure()'
logger.configure(handlers=[
    {"sink": sys.stderr, "backtrace": False},
    {"sink": "protectwise_bootstrap.log", "backtrace": False, "format": "{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}"}
])
2reactions
jonathanhlecommented, Jun 4, 2019

Thanks for your help. Really really lovely loggly module.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python - loguru disable traceback on exceptions
The backtrace attribute controls the length of the traceback (if enabled, Loguru displays the entire traceback instead of stopping at the ...
Read more >
Changelog - loguru documentation
Make the record["exception"] attribute unpackable as a (type, value, traceback) tuple. Fix error happening in some rare circumstances because ...
Read more >
A Complete Guide to Logging in Python with Loguru
backtrace : determines whether the exception trace should extend beyond the point where the error is captured, making it easier to debug.
Read more >
A quick guide to using Loguru - Medium
Not only does it serve as a pseudo-documentation, but it can also be a lifesaver. Returning the right log messages at the right...
Read more >
python-logstash-async from eht16 - GithubHelp
from loguru import logger from logstash_async.handler import ... I want to send environment name with all messages but not able to send it, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found