Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the uses of Null handler in python logging?

Tags:

python

logging

According to python's documentation,

The NullHandler class, located in the core logging package, does not do any formatting or output. It is essentially a ‘no-op’ handler for use by library developers.

If it doesn't print to anything, what is the use of this handler at all? Why would one go to lengths to write loggers and then use null handler to not print anything?

like image 215
InAFlash Avatar asked Oct 28 '25 17:10

InAFlash


1 Answers

So you can keep your logger.warning('Whatever') statements in your code, but conditionally inject a logger that entirely disregards them if you don't want a log in certain situations.

like image 57
deceze Avatar answered Oct 31 '25 08:10

deceze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!