Skip to content

Instantly share code, notes, and snippets.

@webghostx
Created January 28, 2017 16:19
Show Gist options
  • Save webghostx/f4e4231f2dfc542d09484ecfb12c1562 to your computer and use it in GitHub Desktop.
Save webghostx/f4e4231f2dfc542d09484ecfb12c1562 to your computer and use it in GitHub Desktop.
Python Logger mit JSON Konfiguration
import logging
import logging.config
log = logging.getLogger(__name__)
logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": "false",
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
"brief": {
"format": "%(levelname)-9s: %(name)-11s: %(message)s"
},
"precise": {
"format": "%(asctime)-26s %(name)-11s %(levelname)-9s %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"formatter": "precise",
"filename": "app.log",
"maxBytes": 100000,
"backupCount": 2
}
},
"loggers": {
"Main": {
"level": "DEBUG",
"handlers": ["console", "file"],
"propagate": 0
}
},
"root": {
"level": "DEBUG",
"handlers": ["console", "file"]
}
})
log.debug('Debug Note')
log.info('Info Note')
log.warning('Warning Note')
log.error('Error Note')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment