TensorFlow
VLOG
logging
machine learning
tutorial

How to control tensorflow's VLOG?

Master System Design with Codemia

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

Introduction

TensorFlow has two different logging concerns that people often mix together: normal C++ log severity and verbose VLOG output. If you want low-level execution details from TensorFlow internals, you need to configure the C++ logging environment before TensorFlow is imported into the process.

Understand the Relevant Environment Variables

The most commonly used TensorFlow logging variables are:

  • 'TF_CPP_MIN_LOG_LEVEL for normal severity filtering such as INFO, WARNING, and ERROR'
  • 'TF_CPP_MIN_VLOG_LEVEL for verbose VLOG output'
  • 'TF_CPP_VMODULE for enabling verbose logging only in selected C++ source modules'

That distinction matters. Setting TF_CPP_MIN_LOG_LEVEL alone does not enable VLOG.

Set VLOG from the Shell

For one-off debugging, set the variables before running Python:

bash
export TF_CPP_MIN_LOG_LEVEL=0
export TF_CPP_MIN_VLOG_LEVEL=1
python train.py

This tells TensorFlow not to suppress normal INFO logs and to allow verbose logging at level 1 and above.

If you want to target specific internal files instead of turning on verbose logging globally, use TF_CPP_VMODULE:

bash
export TF_CPP_MIN_VLOG_LEVEL=1
export TF_CPP_VMODULE='bfc_allocator=2,gpu_device=2'
python train.py

That is usually much more practical because full verbose output can become enormous.

Set It in Python Before Importing TensorFlow

If you need to configure logging from code, the variables must be defined before import tensorflow as tf.

python
1import os
2
3os.environ["TF_CPP_MIN_LOG_LEVEL"] = "0"
4os.environ["TF_CPP_MIN_VLOG_LEVEL"] = "1"
5os.environ["TF_CPP_VMODULE"] = "bfc_allocator=2"
6
7import tensorflow as tf
8
9print(tf.__version__)

This works because TensorFlow reads these settings during initialization of its native runtime. If you set them after import, the process has usually already committed to its logging behavior.

When to Use TF_CPP_VMODULE

Global VLOG is useful when you are doing short experiments and want broad visibility. In real debugging sessions, per-module selection is better because it limits noise.

Examples of cases where TF_CPP_VMODULE helps:

  • allocator behavior and memory debugging
  • device placement internals
  • graph execution tracing
  • performance investigation for a specific component

The module names correspond to TensorFlow C++ source file basenames without the extension. The exact names depend on the internal component you are trying to inspect.

Keep Python Logging Separate

TensorFlow also has Python-level logging APIs. Those are useful for messages emitted from Python code, but they do not replace C++ VLOG.

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

That changes the Python-facing logger level, not the native verbose logging controlled by TF_CPP_MIN_VLOG_LEVEL.

A good mental model is:

  • Python logger settings affect Python log records
  • 'TF_CPP_* variables affect native TensorFlow runtime logs'

Redirect Output When Debugging Noisy Runs

Verbose TensorFlow logging can be overwhelming, especially during training loops. Redirecting the process output to a file is often the difference between useful tracing and unreadable terminal spam.

bash
export TF_CPP_MIN_VLOG_LEVEL=2
python train.py > tf-debug.log 2>&1

That gives you a searchable record you can inspect after the run.

This also matters in notebook-driven workflows. If you launch TensorFlow from Jupyter without planning for output volume, verbose runtime messages can make the notebook itself hard to use. In those cases, it is often better to reproduce the issue from a plain shell command.

Common Pitfalls

  • Setting the environment variables after importing TensorFlow.
  • Confusing TF_CPP_MIN_LOG_LEVEL with TF_CPP_MIN_VLOG_LEVEL.
  • Enabling global verbose logging when a targeted TF_CPP_VMODULE setting would be more useful.
  • Expecting Python logger configuration to control C++ VLOG.
  • Leaving verbose logging enabled in normal runs and then wondering why performance or readability suffers.

Summary

  • Use TF_CPP_MIN_VLOG_LEVEL to enable TensorFlow C++ verbose logging.
  • Use TF_CPP_VMODULE to focus verbose logging on selected internal modules.
  • Set the environment variables before importing TensorFlow.
  • Keep Python logging configuration separate from C++ runtime logging.
  • Prefer targeted verbose logging over global noisy output whenever possible.

Course illustration
Course illustration

All Rights Reserved.