Skip to content

Instantly share code, notes, and snippets.

@barend
Last active November 16, 2015 09:16
Show Gist options
  • Save barend/52f58ada8c22c2a78ced to your computer and use it in GitHub Desktop.
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().
{
"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
}
}
}
#!/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