Created
July 13, 2017 07:24
-
-
Save chenyg0911/9eb2133d7379ac0fc9c76068ce00b62b to your computer and use it in GitHub Desktop.
python logging config
This file contains hidden or 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
| # -*- coding: utf-8 -*- | |
| import logging | |
| import logging.config | |
| logging.addLevelName(5, 'TRACE') | |
| logging.addLevelName(30, 'WARN') | |
| logging.addLevelName(50, 'FATAL') | |
| logging.config.fileConfig('mylogging.conf') | |
| logger = logging.getLogger('root') | |
| logger.info('working...') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mylogging.conf
`
[loggers]
keys=root
[handlers]
keys=consoleHandler, fileHandler
[formatters]
keys=simpleFormatter
[logger_root]
#level=ERROR
level=DEBUG
handlers=consoleHandler, fileHandler
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)
[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
args=('mylogging.log', 'a')
[formatter_simpleFormatter]
#format=%(asctime)s [%(levelname)-5s] %(name)s %(message)s
format=%(asctime)s.%(msecs)03d [%(levelname)s] %(message)s
datefmt= %Y-%m-%d %H:%M:%S
#datefmt=
`