O que são Logs?
Níveis de log

import logging
logging.warning('Watch out!') # will print a message to the console
logging.info('I told you so') # will not print anythingWARNING:root:Watch out!Exemplo simples
logging_example.py
Escrevendo em um arquivo
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')DEBUG:root:This message should go to the log file
INFO:root:So should this
WARNING:root:And this, toologging_file_example.py
example.log
Dados variáveis
import logging
logging.warning('%s before you %s', 'Look', 'leap!')WARNING:root:Look before you leap!Formatando mensagens
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
logging.debug('This message should appear on the console')
logging.info('So should this')
logging.warning('And this, too')DEBUG:This message should appear on the console
INFO:So should this
WARNING:And this, tooimport logging
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S')
logging.warning('is when this event was logged.')2010-12-12 11:41:42 is when this event was logged.
deck
By Jean Oliveira Rodrigues
deck
- 416