Why Ansible execution log is recorded four times ?

I put log function into ansible code.

and log is repeated four times.

Are there anybody know about this happening ?

Could you post a link to your changes that add a log function?

Usually items being logged multiple times means there are duplicate log handlers attached to the loggers.

For the most part, a log handler will only need to be attached to the ‘ansible’ logger [1], if you are using the

standard ‘logger = logging.getLogger(name)’ or similar.

If your code is adding loggers that set the ‘propagate’ attribute, that could also cause similar behavior. That can cause log records to be handled by handlers attached to multiple loggers. Typically that would show up with a handler attached to some app logger (getLogger(‘ansible’) for ex) as well as the ‘root’ logger, causing the same logRecord to be logged multiple times.

For log configuration troubleshooting, I highly recommend the ‘logging_tree’ module (https://pypi.python.org/pypi/logging_tree)

The easiest way to use it is:

  • ‘import logging_tree’ somewhere (I usually import it in bin/ansible)

  • after your logging setup is run, call:

logging_tree.printout()

That will print to stdout a text diagram showing how logging has been configured (including inherited levels and handlers, etc).

[1] Ok, that part isn’t completely true, because of the way ‘ansible.utils.display’ creates and uses Loggers with names like ‘p=1234 u=alikins’, which is very wrong. But the loggers used there are more or less only meant to be used from the display code to also log ‘displayed’ messages and not as general purpose loggers

Thank you, I have solved the problem because of your reply.

My mistake is that i used same log hanler. For example.

In module_utils > network.py

logger = logging.getLogger(‘log’)

In module_utils > netcfg.py

logger = logging.getLogger(‘log’)

I used like above, so log is recorded more then once.

Thank you Adrian Likins. You help me save my time.

2017년 6월 26일 월요일 오후 10시 25분 1초 UTC+9, Adrian Likins 님의 말: