jonfroehlich wrote: > I am a relative newbie to Python and its logging infrastructure; > however, I have programmed extensively with Java/C# and log4j and > log4net. That, I suppose, could be the root of my problem :) > > I am trying to setup one logger per module (as this is roughly > analogous to how I've used log4j/log4net). However, I've noticed that > my loggers have the disabled flag set to true (more accurately, 1) > when they are initialized. For each logger, do I have to force > disabled = False? To make this more concrete, here is an example. > > In example.py: > > import logging > import logging.config > > _log = logging.getLogger("prediction.predict") > > def main(): > logging.config.fileConfig('logconfig.conf') > _log.warn("test warning!") > > if __name__ == "__main__": > main() > > Unfortunately, this does not print out "test warning!" and if I put a > breakpoint at the _log.warn("test warning!") line, _log.disabled > equals 1. If I change main to: > > def main(): > logging.config.fileConfig('predict_logconfig.conf') > _log.disabled = False > _log.warn("test warning!") > > It works! So, am I doing something wrong or do I always have to force > my loggers to be enabled? Should I update my configuration file so > that loggers start as enabled? Here is my config file
I think you have to put the logger into your config file to avoid that it will be disabled by fileConfig(): > (logconfig.conf): > > [formatters] > keys: detailed,simple > > [handlers] > keys: console,filelog [loggers] keys: root, predict # ... [logger_predict] qualname: prediction.predict handlers: Peter -- http://mail.python.org/mailman/listinfo/python-list