<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes</li>
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Debian 9.0 stretch</li>
<li>Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:</li>
<li>TensorFlow installed from (source or binary):</li>
<li>TensorFlow version (use command below): v1.12.1-2376-gf5ce1c00d4 1.14.0-rc0</li>
<li>Python version: 3.6</li>
<li>Bazel version (if compiling from source):</li>
<li>GCC/Compiler version (if compiling from source):</li>
<li>CUDA/cuDNN version: 10.0/7.6</li>
<li>GPU model and memory: NVIDIA Titan X (Pascal) 12Gb</li>
</ul>
<p dir="auto"><strong>Describe the current behavior</strong><br>
logging from the python's standard library stopped working in TF 1.14. Log file is not created and the output supposed to be written there is instead redirected to the stdout, which results in each logging message appear twice in the console.</p>
<p dir="auto"><strong>Describe the expected behavior</strong><br>
When run on TF 1.12 , log.txt is created and the logging is being recorded correctly.</p>
<p dir="auto"><strong>Code to reproduce the issue</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import logging
import tensorflow as tf


def main(_):
    FORMAT = '%(asctime)-15s %(message)s'
    logging.basicConfig(filename='log.txt', filemode='w',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        level=logging.INFO, format=FORMAT)
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    logging.getLogger('').addHandler(console)

    sess = tf.Session()

    logging.info(&quot;test write&quot;)


if __name__ == '__main__':
    tf.app.run()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">logging</span>
<span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>


<span class="pl-k">def</span> <span class="pl-en">main</span>(<span class="pl-s1">_</span>):
    <span class="pl-v">FORMAT</span> <span class="pl-c1">=</span> <span class="pl-s">'%(asctime)-15s %(message)s'</span>
    <span class="pl-s1">logging</span>.<span class="pl-en">basicConfig</span>(<span class="pl-s1">filename</span><span class="pl-c1">=</span><span class="pl-s">'log.txt'</span>, <span class="pl-s1">filemode</span><span class="pl-c1">=</span><span class="pl-s">'w'</span>,
                        <span class="pl-s1">datefmt</span><span class="pl-c1">=</span><span class="pl-s">'%Y-%m-%d %H:%M:%S'</span>,
                        <span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-s1">logging</span>.<span class="pl-v">INFO</span>, <span class="pl-s1">format</span><span class="pl-c1">=</span><span class="pl-v">FORMAT</span>)
    <span class="pl-s1">console</span> <span class="pl-c1">=</span> <span class="pl-s1">logging</span>.<span class="pl-v">StreamHandler</span>()
    <span class="pl-s1">console</span>.<span class="pl-en">setLevel</span>(<span class="pl-s1">logging</span>.<span class="pl-v">INFO</span>)
    <span class="pl-s1">logging</span>.<span class="pl-en">getLogger</span>(<span class="pl-s">''</span>).<span class="pl-en">addHandler</span>(<span class="pl-s1">console</span>)

    <span class="pl-s1">sess</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>()

    <span class="pl-s1">logging</span>.<span class="pl-en">info</span>(<span class="pl-s">"test write"</span>)


<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-s1">tf</span>.<span class="pl-s1">app</span>.<span class="pl-en">run</span>()</pre></div>
<p dir="auto">This yields the following output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2019-06-16 17:54:24.047410: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10711 MB memory) -&gt; physical GPU (device: 0, name: TITAN X (Pascal), pci bus id: 0000:04:00.0, compute capability: 6.1)
I0616 17:54:24.051054 140454010144128 test_logging.py:15] test write
test write"><pre class="notranslate"><code class="notranslate">2019-06-16 17:54:24.047410: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10711 MB memory) -&gt; physical GPU (device: 0, name: TITAN X (Pascal), pci bus id: 0000:04:00.0, compute capability: 6.1)
I0616 17:54:24.051054 140454010144128 test_logging.py:15] test write
test write
</code></pre></div>
<p dir="auto">Notice that <code class="notranslate">test write</code> appears twice in the output. And log.txt is not created. When run with TF 1.12 this code snippets behaves as expected.</p>
<p dir="auto"><em>Please make sure that this is a bug. As per our <a href="https://github.com/tensorflow/tensorflow/blob/master/ISSUES.md">GitHub Policy</a>, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template</em></p>
<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04): mac OS Mojave</li>
<li>TensorFlow installed from (source or binary): pip</li>
<li>TensorFlow version (use command below): 2.0.0 alpha-0</li>
<li>Python version: 3.7.2</li>
</ul>
<p dir="auto"><strong>Describe the current behavior</strong><br>
When using Python internal "logging" module with Tensorflow, a logging module emits below warning message.</p>
<blockquote>
<p dir="auto">WARNING: Logging before flag parsing goes to stderr.</p>
</blockquote>
<p dir="auto">Also, it prints out duplicate logging message with my own formatter and something internally defined format(I guess) as below.</p>
<blockquote>
<p dir="auto">$ python3 test.py<br>
[INFO|test.py:29] 2019-03-14 17:30:14,402 &gt;&gt; Hello World.<br>
WARNING: Logging before flag parsing goes to stderr.<br>
I0314 17:30:14.402168 4528047552 test.py:29] Hello World.<br>
[INFO|test.py:30] 2019-03-14 17:30:14,402 &gt;&gt; This is message 1<br>
I0314 17:30:14.402369 4528047552 test.py:30] This is message 1</p>
</blockquote>
<p dir="auto">When I try without importing Tensorflow, then it works properly.</p>
<blockquote>
<p dir="auto">$ python3 test.py<br>
[INFO|test.py:29] 2019-03-14 17:37:40,172 &gt;&gt; Hello World.<br>
[INFO|test.py:30] 2019-03-14 17:37:40,172 &gt;&gt; This is message 1</p>
</blockquote>
<p dir="auto"><strong>Describe the expected behavior</strong><br>
Maybe stream handler is colliding each other.</p>
<p dir="auto"><strong>Code to reproduce the issue</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import logging
import tensorflow as tf

formatter = logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s &gt;&gt; %(message)s')

stream_logger = logging.getLogger('logger_stream')
stream_logger.setLevel(logging.INFO)

# Set handler
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
stream_logger.addHandler(streamHandler)

stream_logger.info(&quot;Hello World&quot;)
stream_logger.info(&quot;This is message 1&quot;)"><pre class="notranslate"><code class="notranslate">import logging
import tensorflow as tf

formatter = logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s &gt;&gt; %(message)s')

stream_logger = logging.getLogger('logger_stream')
stream_logger.setLevel(logging.INFO)

# Set handler
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
stream_logger.addHandler(streamHandler)

stream_logger.info("Hello World")
stream_logger.info("This is message 1")
</code></pre></div>