Skip to content

Instantly share code, notes, and snippets.

@barend
Created November 12, 2015 16:37
Show Gist options
  • Save barend/5773c6dedbc10596d844 to your computer and use it in GitHub Desktop.
Save barend/5773c6dedbc10596d844 to your computer and use it in GitHub Desktop.
Pretty much the same as [carlcarl/python_logging_dict_config][pldc], but doesn't rely on eval().
{
"version": 1,
"disable_existing_loggers": true,
"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"
],
"level": "INFO",
"propagate": false
}
}
}
#!/usr/bin/env python
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