[Tutor] Logging script output

Tobias M. tm at tobix.eu
Sun Dec 15 19:01:49 CET 2013


Hi Reuben,

Yes, I think the logging module is the best way to do it.
And it's pretty easy, see this minimal example:

import logging

logging.basicConfig(filename="foo.log", level=logging.DEBUG)
logging.debug("This is a log message")

The log levels are a great way, to control how much will be logged. So 
you can turn off debug messages by increasing the log level (e.g. to 
logging.INFO).

Note: The above code is just a minimal example. The logging module is 
much more powerful. For example, you could use different loggers for 
different parts of you program.

Regards,
Tobias

On 12/15/2013 06:43 PM, Reuben wrote:
>
> Hi,
>
> What is the best way to log the output of a python script execution.
>
> Do we need to use the logging module of python?
>
> Regards,
> Reuben
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131215/d34f5567/attachment.html>


More information about the Tutor mailing list