Created
January 28, 2017 16:19
Python Logger mit JSON Konfiguration
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
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