Last active
July 7, 2017 06:27
-
-
Save kemingy/5add06cd569cc5bbf53cc336e53c7d47 to your computer and use it in GitHub Desktop.
python logging config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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