Skip to content

Instantly share code, notes, and snippets.

@MCardus
Last active February 28, 2018 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MCardus/8a56557693ee453e100a46046e4fa4c8 to your computer and use it in GitHub Desktop.
Save MCardus/8a56557693ee453e100a46046e4fa4c8 to your computer and use it in GitHub Desktop.
Python logging conf in YML format for generaing JSON logs
version: 1
formatters:
human:
format: |
{
"name" : "%(name)s",
"timestamp" : "%(asctime)s",
"severity" : "%(levelname)s",
"message" : "%(message)s"
}
machine:
format: >
{"name" : "%(name)s", "timestamp" : "%(asctime)s", "severity" : "%(levelname)s", "message" : "%(message)s"}
handlers:
file_info:
class: logging.handlers.RotatingFileHandler
level: INFO
formatter: machine
filename: info.log
maxBytes: 10485760 # 10MB
backupCount: 20
encoding: utf8
file_error:
class: logging.handlers.RotatingFileHandler
level: ERROR
formatter: machine
filename: errors.log
maxBytes: 10485760 # 10MB
backupCount: 20
encoding: utf8
console:
class: logging.StreamHandler
level: DEBUG
formatter: human
stream: ext://sys.stdout
loggers:
simple:
level: DEBUG
handlers: [console]
propagate: no
root:
level: DEBUG
handlers: [console, file_info, file_error]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment