10

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?

4
  • 1
    The standard logging module is very probably completely suitable for your needs. Commented Dec 21, 2011 at 11:36
  • @eumiro: AFAIK it does not support log file cycling out of the box, or does it? Commented Dec 21, 2011 at 11:38
  • @Constantinius - it does have file rotation: docs.python.org/howto/logging-cookbook.html#using-file-rotation Commented Dec 21, 2011 at 11:42
  • 1
    @eumiro: I rest my case :) one never stops learning. Commented Dec 21, 2011 at 11:50

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

Comments

7

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.