Skip to main content

How to Log an Info Message in Python with logger.info

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

An info message records that something went as planned: a file was read, a step finished. logger.info logs one at the INFO level, and it can fill values into the message for you. This guide logs two progress messages, one of them with values, with real output from Python 3.15.2.

Syntax​

Syntax
logger.info(<message>, <value>, ...)
PartWhat it means
loggerA logger from logging.getLogger(<name>)
<message>The text of the message. Each %s in it is a placeholder for one value
<value>, ...Optional. The values for the placeholders, in order

Python's logging reference says info "Logs a message with level INFO on this logger. The arguments are interpreted as for debug()." Under debug(), the values "are merged into msg using the string formatting operator", and "No % formatting operation is performed on msg when no args are supplied." The Logging HOWTO describes the INFO level as "Confirmation that things are working as expected."

The Example​

A script logs two progress messages under the logger name report, as if it were reading a sales file: a plain one, and one with the number of rows and the file name filled in.

Prerequisites​

  • uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

basicConfig sets up logging: level=logging.INFO lets INFO messages through, and format prints each message's level, the logger's name and the message.

progress.py
import logging

logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
logger = logging.getLogger("report")

logger.info("Reading the sales file")
logger.info("Read %s rows from %s", 42, "sales.csv")

The progress.py script in a macOS-style code window: basicConfig with level INFO and a levelname, name and message format, a logger named report, then two logger.info calls, the second with the values 42 and sales.csv.

  • The first call has no values, so its message is logged as it is.
  • The second call has two %s placeholders and two values: 42 goes into the first and "sales.csv" into the second.

Step 2: Run It​

Terminal
uv run python progress.py
Output
INFO report: Reading the sales file
INFO report: Read 42 rows from sales.csv

The terminal after uv run python progress.py: INFO report: Reading the sales file, then INFO report: Read 42 rows from sales.csv.

Both messages appeared at the INFO level, under the name report. In the second one, the placeholders became 42 and sales.csv.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving the level at its defaultThe HOWTO: "The default level is WARNING". Without level=logging.INFO, the script printed nothing from logger.infoPass level=logging.INFO to basicConfig
Passing a value without a %s for itlogger.info("Read rows from the sales file", 42) printed --- Logging error --- and TypeError: not all arguments converted during string formatting (required 0, got 1) instead of the message. The script carried on with the next linePut one %s in the message for each value

Troubleshooting​

SymptomLikely causeFix
logger.info prints nothingThe level is WARNING, the defaultPass level=logging.INFO to basicConfig
--- Logging error ---, then not all arguments converted during string formattingThe call passes more values than the message has %s placeholdersAdd the missing %s, or remove the extra value

FAQ​

When should I use info instead of debug or warning?​

The HOWTO's table of levels answers it. DEBUG is "Detailed information, typically of interest only when diagnosing problems." INFO is "Confirmation that things are working as expected." WARNING is "An indication that something unexpected happened, or indicative of some problem in the near future". So a finished step is INFO, the details you need only while hunting a bug are DEBUG, and anything a person should look at is WARNING or higher.

Why not just use print()?​

A log message carries its level and the logger's name, and raising the level turns INFO messages off without touching the logger.info lines. print() always prints.

Conclusion​

logger.info("Read %s rows from %s", 42, "sales.csv") printed INFO report: Read 42 rows from sales.csv once the level was set to INFO. Use it for routine progress, with one %s for each value.

Additional Resources​