Tensorflow suppresses logging messages bug
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
When TensorFlow seems to hide warnings or diagnostic messages, the problem is often logging configuration rather than a real bug in model execution. TensorFlow writes logs from both Python and native C++ code, so muting one layer does not always affect the other, and setting the wrong level can hide information you actually need.
How TensorFlow Logging Is Split
TensorFlow emits messages from two main places. Python-side messages flow through tf.get_logger() and the standard logging module. Startup messages, device placement notices, and some backend warnings may come from the native runtime instead.
That separation explains why code like tf.get_logger().setLevel("ERROR") can reduce some output while low-level startup messages still appear. The reverse is also true: setting the native log threshold may quiet startup noise but leave Python warnings visible.
Controlling Native TensorFlow Logs
The most common switch is the TF_CPP_MIN_LOG_LEVEL environment variable. It must be set before TensorFlow is imported, otherwise the runtime has already initialized.
Typical values are:
- '
0for all messages' - '
1to hide informational messages' - '
2to hide informational messages and warnings' - '
3to hide informational messages, warnings, and most errors'
Using 3 is usually too aggressive during development because it can mask problems that would have helped you debug an environment or model issue.
Controlling Python-Side Logs
After import, you can tune TensorFlow’s Python logger like any other logger. This is useful when training output is buried under repeated warnings from your own code or from TensorFlow wrappers.
This does not change the semantics of training. It only changes what reaches the console.
A Practical Debugging Pattern
If you suspect TensorFlow is suppressing output unexpectedly, start from the least restrictive configuration and tighten it step by step. That makes it much easier to see which layer is muting the message.
If the custom logger.info line appears but native startup messages do not, your native log threshold is the place to investigate. If neither appears, a notebook configuration, wrapper script, or external logging policy may be swallowing stdout or stderr.
Why This Looks Like a Bug
The confusion usually comes from import order and execution environments. In notebooks, cells may import TensorFlow earlier than you realize, so later attempts to set TF_CPP_MIN_LOG_LEVEL do nothing. In larger applications, another module may configure the root logger first. In test runners, output capture can make messages appear to vanish even though TensorFlow still emitted them.
It is also common to copy a snippet from an online answer that sets both the environment variable and the Python logger to the strictest possible setting. That often solves noisy output and then becomes a hidden cause of missing diagnostics weeks later.
Common Pitfalls
The first pitfall is setting TF_CPP_MIN_LOG_LEVEL after import tensorflow as tf. At that point the native runtime is already initialized, so the environment variable is too late.
Another mistake is treating tf.get_logger() as a complete solution. It only controls Python-side logging. Backend messages can still bypass it.
Be careful with level 3. It is tempting when you want a quiet console, but it can hide useful warnings and make environment problems much harder to trace.
Finally, remember that some messages are not from TensorFlow at all. CUDA, cuDNN, oneDNN, and notebook environments may have their own output behavior. If TensorFlow settings do not explain the missing message, inspect the surrounding stack rather than assuming the framework dropped it.
Summary
- TensorFlow logging comes from both Python loggers and the native runtime.
- Set
TF_CPP_MIN_LOG_LEVELbefore importing TensorFlow or it will not affect native startup logs. - Use
tf.get_logger()to control Python-side TensorFlow output after import. - Start with permissive logging when debugging, then reduce noise gradually.
- What looks like a TensorFlow bug is often import order, notebook state, or another logger configuration issue.
Related reading
- Tensorflow Tensor reshape and pad with zeros
- Tensorflow Tensor to numpy array conversion without running any session
- Tensorflow Tensorboard default port
- Tensorflow terminate called after throwing an instance of 'stdsystem_error' what Resource temporarily unavailable
- Tensorflow tf.data AUTOTUNE
- TensorFlow tf.data.Dataset and bucketing
- Tensorflow v1.10 why is an input serving receiver function needed when checkpoints are made without it?
- Terraform - Conditional Data Source

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.