I\'m setting up python logging as follows:
def setup_logging():
loggers = (logging.getLogger(\"amcat\"), logging.getLogger(\"scrapers\"),logging.getLogge
Basically, when one of your child logger displays a message, it goes backwards in the hierarchy, and the parents are also logging the same thing.
To cancel that behavior, you can add this:
logger.propagate = False
When it hits the child, it won't hit the parent afterwards.
Here is some documentation about this behavior.
I figured this out, thanks Paco for pointing me in the right direction
it turns out that when getLogger
is called, handlers are added to it:
>>> print(effectivehandlers(logger))
[<logging.StreamHandler object at 0x305ad90>, <logging.FileHandler object at 0x305ae10>]
>>> logging.getLogger(name) #the same logger
<logging.Logger object at 0x7fa08fb9b2d0>
>>> print(effectivehandlers(logger))
[<logging.StreamHandler object at 0x305ad90>, <logging.FileHandler object at 0x305ae10>, <logging.StreamHandler object at 0x305ad90>, <logging.FileHandler object at 0x305ae10>]
Now, both the child and the parent have the same handlers. Hence duplicate outputs.
for python 2.7
logging.handlers.pop()
Reference by user "radtek": Python Logging - Messages appearing twice