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?
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.
Log messages can have 5 levels - DEBUG, INGO, WARNING, ERROR and CRITICAL. They can also include traceback information for exceptions.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With