Skip to content

Instantly share code, notes, and snippets.

@olivx
Last active August 11, 2020 14:00
Show Gist options
  • Save olivx/4b7360f07c9018f2c4de02826d0b084d to your computer and use it in GitHub Desktop.
Save olivx/4b7360f07c9018f2c4de02826d0b084d to your computer and use it in GitHub Desktop.
python json logger
python-json-logger = "*"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"json": {
"()": "pythonjsonlogger.jsonlogger.JsonFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
}
},
"handlers": {
"stream": {
"level": LOG_LEVEL,
"formatter": "json",
"class": "logging.StreamHandler",
},
"gunicorn-file-stream": {
"level": LOG_LEVEL,
"formatter": "json",
"class": "logging.handlers.RotatingFileHandler",
"filename": "/var/log/app/gunicorn.log",
"maxBytes": 10_000_000,
"backupCount": 3,
},
"app-file-stream": {
"level": LOG_LEVEL,
"formatter": "json",
"class": "logging.handlers.RotatingFileHandler",
"filename": "/var/log/app/app.log",
"maxBytes": 10_000_000,
"backupCount": 3,
},
},
"loggers": {
"django": {"handlers": ["stream", "app-file-stream"], "level": LOG_LEVEL},
"gunicorn": {
"handlers": ["stream", "gunicorn-file-stream"],
"level": LOG_LEVEL,
},
"feira": {"handlers": ["stream", "app-file-stream"], "level": LOG_LEVEL},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment