Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > A new way to configure Python logging

Reply
Thread Tools

A new way to configure Python logging

 
 
Vinay Sajip
Guest
Posts: n/a
 
      10-22-2009
If you use the logging package but don't like using the ConfigParser-based
configuration files which it currently supports, keep reading. I'm proposing to
provide a new way to configure logging, using a Python dictionary to hold
configuration information. It means that you can convert a text file such as

# logconf.yml: example logging configuration
formatters:
brief:
format: '%(levelname)-8s: %(name)-15s: %(message)s'
precise:
format: '%(asctime)s %(name)-15s %(levelname)-8s %(message)s'
handlers:
console:
class : logging.StreamHandler
formatter : brief
level : INFO
stream : ext://sys.stdout
file:
class : logging.handlers.RotatingFileHandler
formatter : precise
filename : logconfig.log
maxBytes : 1000000
backupCount : 3
email:
class: logging.handlers.SMTPHandler
mailhost: localhost
fromaddr:
toaddrs:
-
-
subject: Houston, we have a problem.
loggers:
foo:
level : ERROR
handlers: [email]
bar.baz:
level: WARNING
root:
level : DEBUG
handlers : [console, file]
# -- EOF --

into a working configuration for logging. The above text is in YAML format, and
can easily be read into a Python dict using PyYAML and the code

import yaml; config = yaml.load(open('logconf.yml', 'r'))

but if you're not using YAML, don't worry. You can use JSON, Python source code
or any other method to construct a Python dict with the configuration
information, then call the proposed new configuration API using code like

import logging.config

logging.config.dictConfig(config)

to put the configuration into effect.

For full details of the proposed change to logging, see PEP 391 at

http://www.python.org/dev/peps/pep-0391/

I need your feedback to make this feature as useful and as easy to use as
possible. I'm particularly interested in your comments about the dictionary
layout and how incremental logging configuration should work, but all feedback
will be gratefully received. Once implemented, the configuration format will
become subject to backward compatibility constraints and therefore hard to
change, so get your comments and ideas in now!

Thanks in advance,


Vinay Sajip


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
logging.config.fileConfig FileHandler configure to write to APP_DATA Jeffrey Britton Python 3 04-18-2012 06:12 PM
howto configure logging via yaml Holger K. Ruby 1 12-14-2009 02:47 PM
Re: A new way to configure Python logging Vinay Sajip Python 0 10-24-2009 07:54 AM
Configure logging and audit on routers Esteban G. Cisco 0 03-17-2009 07:57 PM
different between configure libraries and configure JDKs HS1 Java 0 11-18-2004 03:40 AM



Advertisments