tensorflow
logging
error
troubleshooting
debugging

Tensorflow logging messages do not appear

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When TensorFlow log messages do not appear, the problem is usually not that logging is broken. More often, the messages are being filtered, sent through a different logger than expected, or suppressed by environment settings that were applied before TensorFlow initialized.

TensorFlow logging is a mix of Python-level logging and lower-level native logging. That means debugging it requires checking both the Python logger configuration and environment variables such as TF_CPP_MIN_LOG_LEVEL.

Start with the Python Logger

TensorFlow exposes a standard logger:

python
1import tensorflow as tf
2
3logger = tf.get_logger()
4logger.setLevel("INFO")
5logger.info("TensorFlow logger is active")

If that message does not appear, the issue may be your Python logging configuration rather than TensorFlow itself. In many scripts, adding a basic logging setup is enough:

python
1import logging
2import tensorflow as tf
3
4logging.basicConfig(level=logging.INFO)
5
6logger = tf.get_logger()
7logger.setLevel(logging.INFO)
8logger.info("Logging should now be visible")

This handles the Python side of the problem.

Check TF_CPP_MIN_LOG_LEVEL

TensorFlow's native C++ logs are controlled by the TF_CPP_MIN_LOG_LEVEL environment variable. If it is set too aggressively, lower-level logs disappear before Python even has a chance to display them.

Typical meanings are:

  • '0 shows all logs'
  • '1 hides informational logs'
  • '2 hides informational and warning logs'
  • '3 hides informational, warning, and many error logs'

Set it before importing TensorFlow:

python
1import os
2
3os.environ["TF_CPP_MIN_LOG_LEVEL"] = "0"
4
5import tensorflow as tf

If you set the variable after importing TensorFlow, it may be too late because the runtime has already initialized.

Make Sure the Message Is Using the Expected Logger

Not every message in a TensorFlow program goes through the same path. Some messages come from:

  • 'tf.get_logger()'
  • Python's root logger
  • native TensorFlow runtime output
  • notebook or IDE-specific output capture

For example:

python
1import logging
2import tensorflow as tf
3
4logging.warning("root logger warning")
5tf.get_logger().warning("tensorflow warning")
6print("plain print")

If one appears and another does not, that tells you which layer is misconfigured.

Notebooks and IDEs Can Change Output Behavior

Jupyter notebooks, IDE consoles, and test runners often capture or redirect stdout and stderr. A message that appears in a plain terminal script may not appear the same way inside a notebook cell.

If you suspect output capture, run a minimal script from a terminal:

python
1import os
2import logging
3
4os.environ["TF_CPP_MIN_LOG_LEVEL"] = "0"
5
6import tensorflow as tf
7
8logging.basicConfig(level=logging.INFO)
9tf.get_logger().setLevel(logging.INFO)
10tf.get_logger().info("TensorFlow info message")

If the terminal version works, the issue is likely the execution environment rather than TensorFlow configuration itself.

Avoid Fighting Two Filters at Once

A common debugging mistake is changing Python log levels while an environment variable is still suppressing native logs, or vice versa. Simplify first:

  1. set TF_CPP_MIN_LOG_LEVEL to 0
  2. configure Python logging with basicConfig
  3. set tf.get_logger() to INFO
  4. test with a tiny standalone script

Once messages appear, add back any filtering you actually want.

Common Pitfalls

  • Setting TF_CPP_MIN_LOG_LEVEL after importing TensorFlow.
  • Configuring only Python logging while native TensorFlow logs are still suppressed.
  • Assuming notebook output matches terminal-script behavior.
  • Expecting every TensorFlow-related message to go through the same logger.
  • Debugging a large training script before proving logging works in a minimal test case.

Summary

  • TensorFlow logging can be affected by both Python logger settings and native runtime filtering.
  • Use tf.get_logger() for Python-level TensorFlow logs.
  • Set TF_CPP_MIN_LOG_LEVEL before importing TensorFlow.
  • Test in a small standalone script if notebooks or IDEs may be capturing output.
  • Debug one logging layer at a time instead of changing several filters blindly.

Course illustration
Course illustration

All Rights Reserved.