0

Dear all,

I am quite confused about the Python logging. I have read and re-read the Python documentation for the Python logging module 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 following code causes fileLogger to log to BOTH a file and the console, how come? It seems to me that a call such as "consoleHandler = llogging.StreamHandler()" affects other loggers, which I do not want.

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)

Thanks for any help, I have spent so long trying to figure this out!

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by akindo
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.