Skip to content

Instantly share code, notes, and snippets.

@chenyg0911
Created July 13, 2017 07:24
Show Gist options
  • Select an option

  • Save chenyg0911/9eb2133d7379ac0fc9c76068ce00b62b to your computer and use it in GitHub Desktop.

Select an option

Save chenyg0911/9eb2133d7379ac0fc9c76068ce00b62b to your computer and use it in GitHub Desktop.
python logging config
# -*- 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...')
@chenyg0911
Copy link
Author

chenyg0911 commented Jul 13, 2017

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=
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment