Reputation: 557
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?
Upvotes: 10
Views: 1227
Reputation: 599946
The standard Python logging
module is explicitly inspired by log4J, so you will almost certainly find it suitable. It has the same hierarchy, and you can define handlers that listen to one or more levels and do something appropriate, whether it's log to a file or to an email address via SMTP. See the Python logging tutorial.
Upvotes: 7
Reputation: 880677
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.
Upvotes: 11