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

Silencing loguru logger #97

Closed
CodingKaiser opened this issue Jul 24, 2024 · 3 comments
Closed

Silencing loguru logger #97

CodingKaiser opened this issue Jul 24, 2024 · 3 comments

Comments

@CodingKaiser
Copy link
Collaborator

Hi @leoschwarz

I have been using bfabricpy2 for a few weeks now. Awesome work! I was able to get rid of quite some redundant code on my end.

But one question: is there a way to completely silence the loguru logging? I would have expected verbose=False to do the trick, but it seems to only affect messages on top of what loguru already outputs.

Thanks in advance.

All the best,
Falko

@leoschwarz
Copy link
Collaborator

leoschwarz commented Aug 5, 2024

Hi Falko, thank you for opening the issue.

Logging has not been refactored completely yet

  • most messages are INFO level even though some could be demoted to debug
  • as you have seen, verbose=True leads to extra output that is printed to standard error which is currently used for command line scripts, maybe (I'm considering it since it would simplify things) we can just send them to loguru.info too. I have just changed that, it will be in the next release that all messages should go through loguru.

There are the following ways to silence it:

  1. The messages are sent to standard error, so you could capture that (mainly useful for shell scripts so you also have it in case there was an exception)

  2. Use a variation of this snippet:

from loguru import logger
logger.remove()
logger.add(sys.stderr, filter="bfabric", level="WARNING", colorize=False)
  1. As a special variation of the snippet in (2.) you could also send the messages to the default logging module if you prefer that, you just have to give a logging.handler.*" instance to logger.addinstead ofsys.stderr`.

@leoschwarz
Copy link
Collaborator

But this is from their docs, they say we should just disable logging in the library and make it opt in for applications

# For libraries, should be your library's `__name__`
logger.disable("my_library")
logger.info("No matter added sinks, this message is not displayed")

# In your application, enable the logger in the library
logger.enable("my_library")
logger.info("This message however is propagated to the sinks")

The only reason I am a bit hesitant to have no logging by default, is that I then expect logging messages to not be available in general. You could also take the logger.disable("bfabric") approach, if you want no logs at all.

@leoschwarz
Copy link
Collaborator

I've created a short section in the documentation on the logger:

https://fgcz.github.io/bfabricPy/good_to_know/#logging-level

It can be refined later if necessary.

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

No branches or pull requests

2 participants