TensorFlow
logging
suppression
verbose
tutorial

How to suppress verbose Tensorflow logging?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

TensorFlow can produce verbose startup and runtime logs from both Python and native C plus plus layers. While useful for debugging, noisy logs make notebook output and CI logs harder to read. Suppression should be controlled carefully so you keep critical warnings and errors.

Control Native TensorFlow Log Level

Set TF_CPP_MIN_LOG_LEVEL before importing TensorFlow.

python
1import os
2os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"  # 0 all, 1 INFO off, 2 WARNING off, 3 ERROR only
3
4import tensorflow as tf

If set after import, many startup messages already appeared.

Python Logger Configuration

Tune TensorFlow Python logger separately.

python
1import logging
2import tensorflow as tf
3
4tf.get_logger().setLevel(logging.ERROR)

This helps suppress framework-level Python loggers.

Abseil Logging Interaction

TensorFlow uses absl logging in many paths. For some environments, combining settings improves consistency.

python
import absl.logging
absl.logging.set_verbosity(absl.logging.ERROR)

Apply this only when needed; excessive suppression may hide useful diagnostics.

Shell-Level Configuration

For scripts or CI jobs, set env var at shell level.

bash
export TF_CPP_MIN_LOG_LEVEL=2
python train.py

On Windows PowerShell:

powershell
$env:TF_CPP_MIN_LOG_LEVEL="2"
python train.py

Jupyter and Notebook Context

In notebooks, set env variable in first cell before import tensorflow.

python
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
import tensorflow as tf

If TensorFlow was already imported in the kernel, restart kernel for consistent effect.

Suppress Third-Party Noise Carefully

Some log noise may come from CUDA, oneDNN, or backend libraries. You can reduce console chatter, but avoid hiding genuine compatibility warnings in development.

A practical strategy:

  • development: level one or two
  • CI smoke tests: level two
  • production pipelines: retain error visibility

Example Minimal Logging Setup

python
1import os
2import logging
3
4os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
5
6import tensorflow as tf
7
8tf.get_logger().setLevel(logging.ERROR)
9
10print(tf.__version__)

This keeps output concise while preserving critical failures.

TensorFlow OneDNN and Backend Messages

Some startup messages come from backend optimization libraries rather than core logger channels. You may still see notices depending on build and environment.

Use suppression pragmatically, then keep a debug mode script that runs with full logs for troubleshooting.

Reusable Logging Setup Function

python
def configure_tf_logging(level="2"):
    import os
    os.environ["TF_CPP_MIN_LOG_LEVEL"] = level

Call this before TensorFlow import in entrypoint scripts.

CI Pipeline Recommendation

In CI, keep errors visible while reducing informational noise. Store full logs as artifacts for failed jobs so deeper analysis remains possible without noisy normal runs.

Validate behavior with integration tests and realistic data before production rollout.

Command-Line Noise Separation

When training scripts are wrapped by orchestration tools, route TensorFlow logs to dedicated files while keeping concise console output.

This preserves debuggability without overwhelming real-time terminal monitoring.

Keep a separate debug profile with minimal suppression for diagnosing driver and runtime compatibility issues.

Document this configuration for team consistency.

Keep one documented logging preset for development and one for production training pipelines.

Validate suppression settings in container and notebook environments separately.

Review periodically.

Keep alignment.

Always.

Common Pitfalls

  • Setting suppression variables after importing TensorFlow.
  • Hiding too much and missing important runtime warnings.
  • Confusing native C plus plus logs with Python logger output.
  • Expecting one setting to silence all third-party backend messages.
  • Applying aggressive suppression in debugging sessions.

Summary

  • Suppress TensorFlow verbosity by configuring environment and logger settings early.
  • Set TF_CPP_MIN_LOG_LEVEL before import for native log control.
  • Use Python logger levels for framework-level messages.
  • Restart notebook kernels when imports happened before config.
  • Balance clean output with visibility into real operational issues.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice ML system design

All Rights Reserved.