Created
June 2, 2019 07:41
-
-
Save KentaYamada/d94a675099f81d7896968ce92bb2deef to your computer and use it in GitHub Desktop.
python logging config from json
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
{ | |
"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"] | |
} | |
} | |
} |
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 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