Skip to content

Instantly share code, notes, and snippets.

@s-hiiragi
Created December 28, 2021 15:39
Show Gist options
  • Save s-hiiragi/f0c364dc6543b8ed517321389b864ca2 to your computer and use it in GitHub Desktop.
Save s-hiiragi/f0c364dc6543b8ed517321389b864ca2 to your computer and use it in GitHub Desktop.
(Python) 外部ファイルからログレベルを変更するサンプル
{
"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"
}
}
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