Standard way of configuring logging
Bug #310774 reported by
Jonathan Lange
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lazr.config |
Fix Released
|
Medium
|
Barry Warsaw |
Bug Description
It's useful to be able to set:
- log file location
- severity level cutoff
- rotation policy
- how often
- how are files renamed
- how many old files are kept
in a configuration file that can be easily edited by sysadmins, rather than in Python code that constructs and assembles logging.Handler objects.
Changed in lazr.config: | |
assignee: | nobody → barry |
importance: | Undecided → Medium |
status: | New → Triaged |
To post a comment you must log in.
Jono, let me understand better what you're thinking about. I have some similar code in Mailman, but I'm trying to think about how to generalize this. In my schema.conf file I have the following:
{{{
[logging.template]
# This defines various log settings. The options available are:
#
# - level -- Overrides the default level; this may be any of the
# standard Python logging levels, case insensitive.
# - format -- Overrides the default format string
# - datefmt -- Overrides the default date format string
# - path -- Overrides the default logger path. This may be a relative
# path name, in which case it is relative to Mailman's LOG_DIR,
# or it may be an absolute path name. You cannot change the
# handler class that will be used.
# - propagate -- Boolean specifying whether to propagate log message from this
# logger to the root "mailman" logger. You cannot override
# settings for the root logger.
#
# In this section, you can define defaults for all loggers, which will be
# prefixed by 'mailman.'. Use subsections to override settings for specific
# loggers. The names of the available loggers are:
#
# - archiver -- All archiver output
# - bounce -- All bounce processing logs go here
# - config -- Configuration issues
# - debug -- Only used for development
# - error -- All exceptions go to this log
# - fromusenet -- Information related to the Usenet to Mailman gateway
# - http -- Internal wsgi-based web interface
# - locks -- Lock state changes
# - mischief -- Various types of hostile activity
# - post -- Information about messages posted to mailing lists
# - qrunner -- qrunner start/stops
# - smtp -- Successful SMTP activity
# - smtp-failure -- Unsuccessful SMTP activity
# - subscribe -- Information about leaves/joins
# - vette -- Information related to admindb activity
format: %(asctime)s (%(process)d) %(message)s
datefmt: %b %d %H:%M:%S %Y
propagate: no
level: info
path: mailman
[logging.root]
[logging.archiver]
[logging.bounce]
path: bounce
[logging.config]
[logging.debug]
path: debug
level: debug
[logging.error]
[logging. fromusenet]
[logging.http]
[logging.locks]
[logging.mischief]
[logging.qrunner]
[logging.smtp]
path: smtp
[logging.subscribe]
[logging.vette]
}}}
then in my logger initialize code, I've got something like this:
{{{ basicConfig( format= config. logging. root.format,
datefmt= config. logging. root.datefmt,
level= as_log_ level(config. logging. root.level) ) logger_ configs: config. name.split( '.')[-1] getLogger( logger_ name) config. format
# First, find the root logger and configure the logging subsystem.
# Initialize the root logger, then create a formatter for all the sublogs.
logging.
# Create the subloggers
for logger_config in config.
logger_name = 'mailman.' + logger_
log = logging.
# Get settings from log configuration file (or defaults).
log_format = logger_
log_dat...