Skip to content

Instantly share code, notes, and snippets.

@KentaYamada
Created June 2, 2019 07:41
Show Gist options
  • Save KentaYamada/d94a675099f81d7896968ce92bb2deef to your computer and use it in GitHub Desktop.
Save KentaYamada/d94a675099f81d7896968ce92bb2deef to your computer and use it in GitHub Desktop.
python logging config from json
{
"version": 1.0,
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout"
}
},
"loggers": {
"simpleExample": {
"level": "DEBUG",
"handlers": ["console"],
"propagate": "no"
},
"root": {
"level": "DEBUG",
"handlers": ["console"]
}
}
}
import json
import logging
import logging.config
if __name__ == '__main__':
config = None
with open('logging-config.json') as f:
config = json.load(f)
logging.config.dictConfig(config)
logger = logging.getLogger('simpleExample')
logger.debug('hoge')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment