There are really two logging systems in tensorflow: one in the C++ core (specifically tensorflow/core/platform/default/logging.{h,cc}) and the other in the Python bindings. The two systems are independent.
The one in the Python binding plays nicely with the standard Python logging module. The C++ logger is indepedently controlled by the TF_CPP_MIN_LOG_LEVEL
environment variables mentioned in previous answers.
The following Python (that I locally called logtest.py) demonstrates the two systems' independence.
"""
Demonstrate independence of TensorFlow's two logging subsystems.
"""
import argparse
import tensorflow as tf
import logging
_logger = logging.getLogger( "tensorflow" )
parser = argparse.ArgumentParser( description="Demo TensorFlow logging" )
parser.add_argument("-v","--verbosity",
default="",
choices=['DEBUG','INFO','WARNING','ERROR','CRITICAL'],
help="One of {DEBUG,INFO,WARNING,ERROR,CRITICAL}" )
args = parser.parse_args()
print( "Initial Python effective log level:", _logger.getEffectiveLevel() )
# If user provided an explicit Python level, set it.
if args.verbosity:
_logger.setLevel( args.verbosity )
print( " ...new Python effective log level:", _logger.getEffectiveLevel() ) # ...and confirm the change.
_logger.debug( " DEBUG messages are emitted" )
_logger.info( " INFO messages are emitted" )
_logger.warn( " WARNING messages are emitted" )
_logger.error( " ERROR messages are emitted" )
_logger.critical( "CRITICAL messages are emitted" )
with tf.Session() as s:
pass # ...just to trigger TensorFlow into action to generate logging.
Running...
TF_CPP_MIN_LOG_LEVEL=0 python3 logtest.py -v CRITICAL
...shows that Python can't silence the core logging system, and
TF_CPP_MIN_LOG_LEVEL=5 python3 logtest.py -v DEBUG
...shows that the core system can't silence Python.