Tensorflow causes logging messages to double

logger.propagate = False solved my problem. I think this is a bug of tensorflow


I get this output:

test
WARNING:TEST:test

Tensorflow is also using the logging framework and has set up its own handlers, so when you log, by default, it propagates up to the parent logging handlers inside tensorflow. You can change this behavior by setting:

logger.propagate = False

See also duplicate output in simple python logging configuration

Followup: This was an unintended side-effect of the way tensorflow was using the logging package. I've changed it at HEAD to scope its internal loggers under the name "tensorflow" to avoid this pollution. Should be in the github head within a day or so. In the meantime, the logger.propagate solution will work and won't break once that fix is in, so you should be safe to go. Thanks again for spotting this!

Followup-Followup: Starting with TensorFlow 1.14 exposes the logger directly:

import tensorflow as tf

logger = tf.get_logger()