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:
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:
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:
- '
0shows all logs' - '
1hides informational logs' - '
2hides informational and warning logs' - '
3hides informational, warning, and many error logs'
Set it before importing TensorFlow:
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:
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:
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:
- set
TF_CPP_MIN_LOG_LEVELto0 - configure Python logging with
basicConfig - set
tf.get_logger()toINFO - test with a tiny standalone script
Once messages appear, add back any filtering you actually want.
Common Pitfalls
- Setting
TF_CPP_MIN_LOG_LEVELafter 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_LEVELbefore 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.

