tensorflow
tf.logging
set_verbosity
logging level
code explanation

What does that code snippet signify tf.logging.set_verbositytf.logging.INFO in tensorflow code?

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

tf.logging.set_verbosity(tf.logging.INFO) is a TensorFlow 1.x style logging call. It tells TensorFlow to emit messages at the INFO level and above, which usually means you will see informational, warning, error, and fatal messages, but not debug-level noise.

What It Means in TensorFlow 1.x

TensorFlow 1.x exposed a logging API through tf.logging. The set_verbosity function sets the minimum severity level that the TensorFlow logger should print. When the level is INFO, ordinary status messages become visible.

That matters for old training scripts because many helper APIs log useful progress only at INFO. If the verbosity is higher, such as WARN, those messages are suppressed and the script can look silent even though it is working.

Here is a minimal example using the compatibility namespace that still exists in current TensorFlow:

python
1import tensorflow as tf
2
3tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.INFO)
4
5tf.compat.v1.logging.debug("debug message")
6tf.compat.v1.logging.info("training has started")
7tf.compat.v1.logging.warn("learning rate is very small")

With the level set to INFO, the debug message is hidden, while the info and warn messages are shown.

The Logging Levels

The levels are ordered from least severe to most severe:

  • 'DEBUG'
  • 'INFO'
  • 'WARN'
  • 'ERROR'
  • 'FATAL'

Think of set_verbosity as a threshold. Messages below the threshold are dropped. Messages at or above it are emitted.

This is why INFO is a common default in examples. It gives you progress updates without the volume of DEBUG.

The Modern TensorFlow 2 Equivalent

In TensorFlow 2, the old tf.logging namespace is legacy code. Newer code usually goes through tf.get_logger() or plain Python logging. If you are reading a current codebase, that is the style you are more likely to see.

python
1import logging
2import tensorflow as tf
3
4logger = tf.get_logger()
5logger.setLevel(logging.INFO)
6
7logger.info("dataset loaded")
8logger.debug("hidden unless level is DEBUG")

This modern form expresses the same basic intent: show INFO and more severe messages.

There is one more layer to be aware of. Some TensorFlow runtime messages come from native code rather than the Python logger. Those are often controlled with the TF_CPP_MIN_LOG_LEVEL environment variable.

bash
export TF_CPP_MIN_LOG_LEVEL=2
python train.py

That example suppresses lower-severity C++ runtime messages. It is useful when startup logs are too noisy, but it is separate from tf.compat.v1.logging.set_verbosity(...).

When You Still See This Snippet

You will still encounter this line in older tutorials, TensorFlow 1.x notebooks, and migration code that lives under tf.compat.v1. It usually exists for one of two reasons:

  1. the author wanted readable training progress in the console
  2. the script relied on hooks or utilities that emit INFO messages

So if you see the snippet in old code, do not over-interpret it. It does not change model math, performance, or randomness. It only changes what gets printed.

Common Pitfalls

A common mistake is assuming this call affects every log source in the process. It does not. Python's standard logging module, TensorFlow compatibility logging, and TensorFlow C++ runtime logs can each have their own controls.

Another mistake is copying tf.logging into modern TensorFlow 2 code without the compatibility namespace. In current TensorFlow, the safe migration path is tf.compat.v1.logging for old code and tf.get_logger() for new code.

Developers also sometimes expect this setting to change Keras progress bars or notebook cell output. Those are separate display mechanisms and may not respond to logger verbosity in the way you expect.

Summary

  • 'tf.logging.set_verbosity(tf.logging.INFO) is a TensorFlow 1.x logging threshold setting.'
  • It enables INFO, WARN, ERROR, and FATAL messages while hiding DEBUG messages.
  • In modern TensorFlow, prefer tf.get_logger().setLevel(logging.INFO).
  • This setting changes console logging, not model behavior.
  • Native TensorFlow runtime logs may require TF_CPP_MIN_LOG_LEVEL instead.

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.