On Jul 31, 2:04 pm, Jean-Michel Pichavant <jeanmic...@sequans.com> wrote: > Jannik Sundø wrote: > > Hi all. I think I fixed this problem by setting fileLogger.propagate = > > 0. Otherwise it will propagate up to the root logger, which outputs to > > stdout, as far as I can understand. > > > On 31 Jul 2009, at 01:17, Jannik Sundø wrote: > > >> Dear all, I am quite confused about the Pythonlogging. I have read > >> and re-read the Python documentation for the Pythonloggingmodule > >> and googled, but to no avail. I simply want one logger to log to a > >> file and another logger to log to the console. Neither should log the > >> other's messages. The code below causes fileLogger to log to BOTH a > >> file and the console, how come? It seems to me that a call such as > >> "consoleHandler =logging.StreamHandler()" affects other loggers, > >> which I do not want. Also, if I do not do > >>logging.basicConfig(level=logging.INFO) in one of the classes of my > >> application, theloggingdoes not work. Any ideas how come? > > >> Thanks a lot for any help! :) > > >> fileHandler =logging.FileHandler('../../logs/log.txt') > >> fileLogger =logging.getLogger('TESTHARNESSFILE') > >> fileLogger.addHandler(fileHandler) > >> fileLogger.setLevel(logging.INFO) > >> consoleHandler =logging.StreamHandler() > >> logger =logging.getLogger('TESTHARNESS') > >> logger.addHandler(consoleHandler) > >> logger.setLevel(logging.INFO) > > > --http://mail.python.org/mailman/listinfo/python-list > > Please do not top post :o) > > Are sure you have used the code provided above ? > Loggers only propagate events to its parent. > > fileLogger =logging.getLogger('TESTHARNESSFILE" > logger =logging.getLogger('TESTHARNESS') > Those one have no parent relationship. > > However these one have parent relationship: > fileLogger =logging.getLogger('TESTHARNESS.FILE") # note the dotted name > logger =logging.getLogger('TESTHARNESS') > > Or maybe you have added a handler to the root logger... > > Using the propagate attribute is correct only between 2 loggers that are > meant to be parents. > > JM
What you say is true, Jean-Michel, but the OP might be meaning the parent-child relationship both his loggers have with the mother of all loggers - the root logger ;-) Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list