RE: How to package a logging.config file?



I had the similar question and my solution is:

default_config = os.path.join(os.getcwd(), "log.config")

def get_logger(name, config_file=None):
if config_file:
logging.config.fileConfig(config_file)
else:
logging.basicConfig(level=logging.INFO,
format='%(levelname)s %(module)s:%(lineno)d:
%(message)s')

return logging.getLogger(name)

I had to make this helper function because calling logging.getLogger
will fail in an exception without configuring logging module. I wish it
is not like that.

BR
Younger Wang
-----Original Message-----
From: python-list-bounces+younger.wang=packetfront.com@xxxxxxxxxx
[mailto:python-list-bounces+younger.wang=packetfront.com@xxxxxxxxxx] On
Behalf Of Matthew Wilson
Sent: Monday, July 14, 2008 8:21 AM
To: python-list@xxxxxxxxxx
Subject: How to package a logging.config file?

I'm working on a package that uses the standard library logging module
along with a .cfg file.

In my code, I use
logging.config.fileConfig('/home/matt/mypackage/matt.cfg') to load in
the logging config file.

However, it seems really obvious to me that this won't work when I share
this package with others.

I can't figure out what path to use when I load my .cfg file.

Any ideas?

Matt
--
http://mail.python.org/mailman/listinfo/python-list
.



Relevant Pages

  • Re: improvements for the logging package
    ... but the logging module seems like such an unpythonic beast to ... > - It's a package, but contrary to any other package I've ever seen, most ... It's partitioned that way so that the most commonly used handlers are ... The code was mostly written before the idea of putting it into Python ...
    (comp.lang.python)
  • Re: improvements for the logging package
    ... but the logging module seems like such an unpythonic beast to ... > it can be used outside the logging package. ... Eschewing PEP ...
    (comp.lang.python)
  • Re: How to package a logging.config file?
    ... I can't figure out what path to use when I load my .cfg file. ... Is your package a library or an application? ... should avoid configuring logging using a config file - this is because ...
    (comp.lang.python)
  • How to package a logging.config file?
    ... I'm working on a package that uses the standard library logging module ... the logging config file. ... I can't figure out what path to use when I load my .cfg file. ...
    (comp.lang.python)