Last active
November 16, 2015 09:16
-
-
Save barend/52f58ada8c22c2a78ced to your computer and use it in GitHub Desktop.
Pretty much the same as carlcarl/python_logging_dict_config, but doesn't rely on eval().
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": true, | |
"filters": { | |
"my_filter": { | |
"()": "filters.MyFilter" | |
} | |
}, | |
"formatters": { | |
"debug": { | |
"format": "[%(levelname)s][%(asctime)s](%(funcName)s/%(lineno)d) %(message)s", | |
"datefmt": "%Y-%m-%d %H:%M:%S" | |
}, | |
"simple": { | |
"format": "[%(levelname)s][%(asctime)s] %(message)s", | |
"datefmt": "%Y-%m-%d %H:%M:%S" | |
} | |
}, | |
"handlers": { | |
"console": { | |
"level": "DEBUG", | |
"class": "logging.StreamHandler", | |
"formatter": "simple" | |
}, | |
"file": { | |
"level": "DEBUG", | |
"class": "logging.handlers.RotatingFileHandler", | |
"filename": "test.log", | |
"formatter": "simple", | |
"maxBytes": 10485760, | |
"backupCount": 100 | |
} | |
}, | |
"loggers": { | |
"my_app": { | |
"handlers": [ | |
"console", | |
"file" | |
], | |
"filters": [ | |
"my_filter" | |
], | |
"level": "INFO", | |
"propagate": false | |
} | |
} | |
} |
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
#!/usr/bin/env python | |
# | |
# ref: https://github.com/carlcarl/python_logging_dict_config/blob/a2c3790d7d5a91b5cfaa55135c4b9a54d6e24101/main.py | |
# | |
# Filters in JSON: | |
# http://stackoverflow.com/a/21464327/49489 | |
# | |
import json | |
from logging.config import dictConfig | |
dictConfig(json.load(file('logging-config.json'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment