Logging en Python

En esta página está muy bien explicado. Dice lo siguiente:

A very common situation is that of recording logging events in a file, so let’s look at that next. Be sure to try the following in a newly-started Python interpreter, and don’t just continue from the session described above:

import logging
logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')

And now if we open the file and look at what we have, we should find the log messages:

DEBUG:root:This message should go to the log file
INFO:root:So should this
WARNING:root:And this, too

import logging
logging.warning(‘%s before you %s’, ‘Look’, ‘leap!’)

will display:

WARNING:root:Look before you leap!

To display the date and time of an event, you would place ‘%(asctime)s’ in your format string:

import logging
logging.basicConfig(format=’%(asctime)s %(message)s’)
logging.warning(‘is when this event was logged.’)

which should print something like this:

2010-12-12 11:41:42,612 is when this event was logged.

Entonces, lo que yo quiero es:

import logging
logging.basicConfig(filename=’example.log’,level=logging.DEBUG,format=’%(asctime)s %(message)s’)
logging.debug(‘%s before you %s’, ‘Look’, ‘leap!’)

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.