TensorFlow logs not showing up in Console and File
<p>this is probably just a stupid mistake on my end, but I can't seem to find it.</p>

<p>I would like to see the logs from TensorFlow on my console and in the log file, which works for all of my code but the TensorFlow part.</p>

<p>I have configured logging like this:</p>

<pre><code>from logging.config import dictConfig
...
# Setup Logging
LOGGING_CONFIG = dict(
    version=1,
    formatters={
        # For files
        'detailed': {'format':
              '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'},
        # For the console
        'console': {'format':
              '[%(levelname)s] %(message)s'}
    },
    handlers={
        'console': {
            'class': 'logging.StreamHandler',
            'level': logging.DEBUG,
            'formatter': 'console',
        },
        'file': {
            'class': 'logging.handlers.RotatingFileHandler',
            'level': logging.DEBUG,
            'formatter': 'detailed',
            'filename': LOG_FILE,
            'mode': 'a',
            'maxBytes': 10485760,  # 10 MB
            'backupCount': 5
        }
    },
    root={
        'handlers': ['console', 'file'],
        'level': logging.DEBUG,
    },
)
dictConfig(LOGGING_CONFIG)
</code></pre>

<p>I researched this problem and learned that I had to enable logging in TensorFlow with something like this:</p>

<pre><code>import tensorflow as tf
...
tf.logging.set_verbosity(tf.logging.INFO)
</code></pre>

<p>Unfortunately this doesn't seem to work - the logs are not showing up. If I use <code>logging.basicConfig()</code> instead of my own configuration, the logs are displayed as expected. In this case the logs are printed to my terminal. </p>

<p>My conclusion is, that my logging configuration is somewhat faulty - please help me.</p>

<p>After reading <a href="https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/" rel="nofollow" title="Good logging practice in Python">Good logging practice in Python</a> I found my mistake. The call to <code>dictConfig</code> disables existing loggers by default - I had to add a another key to the config to resolve this (<code>disable_existing_loggers</code>):</p>

<pre><code># Setup Logging
LOGGING_CONFIG = dict(
    version=1,
    formatters={
        # For files
        'detailed': {'format':
              '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'},
        # For the console
        'console': {'format':
              '[%(levelname)s] %(message)s'}
    },
    handlers={
        'console': {
            'class': 'logging.StreamHandler',
            'level': logging.DEBUG,
            'formatter': 'console',
        },
        'file': {
            'class': 'logging.handlers.RotatingFileHandler',
            'level': logging.DEBUG,
            'formatter': 'detailed',
            'filename': LOG_FILE,
            'mode': 'a',
            'maxBytes': 10485760,  # 10 MB
            'backupCount': 5
        }
    },
    root={
        'handlers': ['console', 'file'],
        'level': logging.DEBUG,
    },
    disable_existing_loggers=False
)
</code></pre>

<p>Now it works :)</p>

python python-3.x logging tensorflow