Skip to content

Instantly share code, notes, and snippets.

@bootandy
Last active August 26, 2021 07:14
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bootandy/5546891 to your computer and use it in GitHub Desktop.
Save bootandy/5546891 to your computer and use it in GitHub Desktop.
Sample logging config file for python logging module
# use with: logging.config.dictConfig(yaml.load(open('logging.yaml', 'r')))
# Formatters detailed here: http://docs.python.org/2/library/logging.html#logrecord-attributes
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
detail:
format: '%(asctime)s - %(levelname)s - File: %(filename)s - %(funcName)s() - Line: %(lineno)d - %(message)s'
loggers:
all:
handlers: [all]
propagate: true
warn:
handlers: [warn]
propagate: true
ingenia:
handlers: [ingenia]
propagate: false # We dont want ingenia logs going everywhere
qualname: ingenia
tornado:
handlers: [all]
propagate: false
handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: simple
stream: ext://sys.stdout
all:
class: logging.handlers.TimedRotatingFileHandler
level: INFO
formatter: simple
when: W0
backupCount: 4
filename: /var/log/grata/all.log
warn:
class: logging.handlers.TimedRotatingFileHandler
level: WARNING
formatter: detail
when: W0
backupCount: 4
filename: /var/log/grata/warn.log
ingenia:
class: logging.handlers.TimedRotatingFileHandler
level: DEBUG
formatter: simple
when: W0
backupCount: 4
filename: /var/log/grata/ingenia.log
root:
level: INFO
handlers: [console, all, warn]
propagate: true
@2shou
Copy link

2shou commented Jan 31, 2015

I tried but didn't log access records of tornado. Why?

@MadCatDestiny
Copy link

What about configure filename in TimedRotatingFileHandler? In code i can add in end time or date in filename. For example: handler = handlers.TimedRotatingFileHandler('config.log'+datetime.datetime.now().strftime('%d-%m-%Y'), when='midnight')
How i can do this in config file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment