Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change logger.exception to level=CRITICAL instead of ERROR?

Tags:

python

I need to change the logger.exception default behavior to write to my logger with level=CRITICAL. It seems like something I can change but I haven't figured out how. My last resort is sys.excepthook but I don't want to use it because I do formatting in there.

thanks!

like image 365
matthewaveryusa Avatar asked Dec 14 '12 23:12

matthewaveryusa


People also ask

Does logging error raise exception?

Logging and raising exceptions are two different things for two different purposes. Logs let you inspect what your program did after the fact. Raising exceptions has important effects on the program flow right now. Sometimes you want one, sometimes you want the other, sometimes you want both.

What does logger exception do?

Logging an exception in python with an error can be done in the logging. exception() method. This function logs a message with level ERROR on this logger. The arguments are interpreted as for debug().

What is except exception as e?

except: accepts all exceptions, whereas. except Exception as e: only accepts exceptions that you're meant to catch. Here's an example of one that you're not meant to catch: >>> try: ...

What does logging getLogger (__ Name __) do?

getLogger(name) is typically executed. The getLogger() function accepts a single argument - the logger's name. It returns a reference to a logger instance with the specified name if provided, or root if not. Multiple calls to getLogger() with the same name will return a reference to the same logger object.


1 Answers

You can log exceptions using CRITICAL like this:

logger.critical('Message with %s', 'arguments', exc_info=True)

which will behave just like logger.exception, only with a level of CRITICAL rather than ERROR.

like image 64
Vinay Sajip Avatar answered Oct 05 '22 00:10

Vinay Sajip