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.

Change level of default handler

See original GitHub issue

First off, this library is terrific, I found it via the podcast Python Bytes and I’ve been using it ever since.

So here is my question: I understand, the default handler for from loguru import logger goes to sys.stderr.

When I try: logger.add(sys.stderr, level="INFO"), I still get DEBUG level messages in the terminal.

My goal is to change the level of the logging to sys.stderr. I don’t have any other handlers.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:19
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

22reactions
jetheurercommented, Feb 7, 2019

@Delgan Thank you! I’ve got

log.remove()
log.add(sys.stderr, level=config.LOG_LEVEL)

in my codebase now. I missed that the .remove() method removes the previously added handler (meaning the default one). For some reason I thought I’d have to know the default handler’s id.

15reactions
Delgancommented, Feb 7, 2019

@jetheurer If no argument is provided to logger.remove(), all existing handlers are removed.

You can also remove the default handler using logger.remove(0), because the default handler will always have the id 0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change the default or package log levels
If you want to change the default/package log level temporally you have to go to Manage Jenkins > System Log > Log Levels...
Read more >
Replace default handler of Python logger - Stack Overflow
You can remove the default handler from the getLogger() using this: logging.getLogger().removeHandler(logging.getLogger().handlers[0]).
Read more >
Logging - Oracle Help Center
To set or change the handler level after the environment is opened, do one of the following: Use EnvironmentMutableConfig.setConfigParam() to change the handler ......
Read more >
How to change log Level in Java Util logging? - LogicBig
To change a log level we must use Logger#setLevel() and Handler#setLevel() . Examples. Programmatically setting Log Level. We are going to set ...
Read more >
Logging HOWTO — Python 3.11.1 documentation
The default level is WARNING , which means that only events of this level and above will be ... Changed in version 3.9:...
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