Issue 1:
System information

Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Debian 9.0 stretch

Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:

TensorFlow installed from (source or binary):

TensorFlow version (use command below): v1.12.1-2376-gf5ce1c00d4 1.14.0-rc0

Python version: 3.6

Bazel version (if compiling from source):

GCC/Compiler version (if compiling from source):

CUDA/cuDNN version: 10.0/7.6

GPU model and memory: NVIDIA Titan X (Pascal) 12Gb

Describe the current behavior

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.

Describe the expected behavior

When run on TF 1.12 , log.txt is created and the logging is being recorded correctly.

Code to reproduce the issue

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("test write")

if __name__ == '__main__':
tf.app.run()

This yields the following output:

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) -> 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

Notice that test write appears twice in the output. And log.txt is not created. When run with TF 1.12 this code snippets behaves as expected.

Issue 2:
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): mac OS Mojave

TensorFlow installed from (source or binary): pip

TensorFlow version (use command below): 2.0.0 alpha-0

Python version: 3.7.2

Describe the current behavior

When using Python internal "logging" module with Tensorflow, a logging module emits below warning message.

WARNING: Logging before flag parsing goes to stderr.

Also, it prints out duplicate logging message with my own formatter and something internally defined format(I guess) as below.

$ python3 test.py

[INFO|test.py:29] 2019-03-14 17:30:14,402 >> Hello World.

WARNING: Logging before flag parsing goes to stderr.

I0314 17:30:14.402168 4528047552 test.py:29] Hello World.

[INFO|test.py:30] 2019-03-14 17:30:14,402 >> This is message 1

I0314 17:30:14.402369 4528047552 test.py:30] This is message 1

When I try without importing Tensorflow, then it works properly.

$ python3 test.py

[INFO|test.py:29] 2019-03-14 17:37:40,172 >> Hello World.

[INFO|test.py:30] 2019-03-14 17:37:40,172 >> This is message 1

Describe the expected behavior

Maybe stream handler is colliding each other.

Code to reproduce the issue

import logging
import tensorflow as tf

formatter = logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(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")