Skip to content

Instantly share code, notes, and snippets.

@kemingy
Last active July 7, 2017 06:27
Show Gist options
  • Save kemingy/5add06cd569cc5bbf53cc336e53c7d47 to your computer and use it in GitHub Desktop.
Save kemingy/5add06cd569cc5bbf53cc336e53c7d47 to your computer and use it in GitHub Desktop.
python logging config
import logging
import logging.config
config = {
'version': 1,
'formatters': {
'simple': {
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'simple',
},
'file': {
'class': 'logging.FileHandler',
'filename': 'logging.log',
'level': 'DEBUG',
'formatter': 'simple',
},
},
'loggers': {
'root': {
'handlers': ['console'],
'level': 'DEBUG',
},
'simple': {
'handlers': ['console', 'file'],
'level': 'WARN',
}
}
}
logging.config.dictConfig(config)
def test_log(name):
print('test log %s' % name)
log = logging.getLogger(name)
log.debug('I am writing bugs...')
log.info('No info for you')
log.warn('Do Not Touch My PC')
log.error('This fucked off')
log.critical('Your PC got fire')
if __name__ == '__main__':
test_log('root')
print('-' * 80)
test_log('simple')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment