I had the similar question and my solution is:
default_config = os.path.join(os .getcwd(), "log.config ")
def get_logger(name , config_file=Non e):
if config_file:
logging.config. fileConfig(conf ig_file)
else:
logging.basicCo nfig(level=logg ing.INFO,
format='%(level name)s %(module)s:%(li neno)d:
%(message)s')
return logging.getLogg er(name)
I had to make this helper function because calling logging.getLogg er
will fail in an exception without configuring logging module. I wish it
is not like that.
BR
Younger Wang
-----Original Message-----
From: py************* *************** *************** ***@python.org
[mailto:py****** *************** *************** **********@pyth on.org] On
Behalf Of Matthew Wilson
Sent: Monday, July 14, 2008 8:21 AM
To:
py*********@pyt hon.org
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