Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging in Python?

Tags:

python

logging

I have used log4J and log4N on previous not-pythonic projects. I like heirachy of warnings,errors and escalations. The ability to log the error and if it is serious email the support team. Also automatic log file cycling is important as the it will be running on a small LINUX device.

Can I do this with the standard Python logging module or is there a better approach?

like image 399
Eric Hewett Avatar asked Dec 21 '11 11:12

Eric Hewett


People also ask

What is a logging in Python?

Python has a built-in module logging which allows writing status messages to a file or any other output streams. The file can contain the information on which part of the code is executed and what problems have been arisen.

What are the five levels of logging in Python?

Log messages can have 5 levels - DEBUG, INGO, WARNING, ERROR and CRITICAL. They can also include traceback information for exceptions.

How important is logging in Python?

Logging is a way to store information about your script and track events that occur. When writing any complex script in Python, logging is essential for debugging software as you develop it. Without logging, finding the source of a problem in your code may be extremely time consuming.


1 Answers

Yes, the logging module has log levels DEBUG, INFO, WARNING, ERROR and CRITICAL. You can setup a SMTPHandler to send mail when the logging level is, say, CRITICAL, and you can setup a RotatingFileHandler to limit the number and size of the log files.

like image 99
unutbu Avatar answered Sep 28 '22 09:09

unutbu