Created
December 28, 2021 15:39
-
-
Save s-hiiragi/f0c364dc6543b8ed517321389b864ca2 to your computer and use it in GitHub Desktop.
(Python) 外部ファイルからログレベルを変更するサンプル
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
{ | |
"version": 1, | |
"disable_existing_loggers": false, | |
"formatters": { | |
"default": { | |
"format": "%(levelname)s:%(name)s:%(message)s" | |
} | |
}, | |
"handlers": { | |
"console": { | |
"class": "logging.StreamHandler", | |
"formatter": "default" | |
} | |
}, | |
"loggers": { | |
"__main__": { | |
"handlers": ["console"], | |
"propagate": true | |
} | |
}, | |
"root": { | |
"level": "DEBUG" | |
} | |
} |
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
import json | |
import logging | |
import logging.config | |
with open('conf.json') as f: | |
conf = json.load(f) | |
logging.config.dictConfig(conf) | |
logger = logging.getLogger(__name__) | |
logger.debug('DEBUG') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment