CodeBlanks Logo Icon CodeBlanks

Log levels

Learn debug, info, warning, error, critical levels.

Log levels

Logging uses one of five levels: debug (10), info (20), warning (30), error (40), critical (50). The logger's level decides which messages are written.

logger.debug("ayıklama")     # 10
logger.info("bilgi")        # 20
logger.warning("uyarı")     # 30
logger.error("hata")        # 40
logger.critical("kritik")   # 50

Low-level messages (debug, info) are rarely used in production; high-level ones (error, critical) are always written.

Order and priority

Each level has a numeric value: DEBUG=10, INFO=20, WARNING=30, ERROR=40, CRITICAL=50. The logger writes only messages whose level is equal to or higher than its own.

logger.setLevel(logging.WARNING)
logger.debug("invisible")   # skipped
logger.warning("visible")   # written

This is used to silence low-level messages in production; during debugging you lower the level to DEBUG.

Practice Print level values

Start with import logging. Print the numeric values of the first three levels with print(logging.DEBUG), print(logging.INFO) and print(logging.WARNING).

Starter code

main.py
# import the logging module
# print the numeric values of DEBUG, INFO and WARNING

Sample solution

main.py
import logging

print(logging.DEBUG)
print(logging.INFO)
print(logging.WARNING)

Expected output

10
20
30

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Complete the info call

Question
logger.____("bilgi")
Answer
logger.info("bilgi")

Explanation: logger.info(...) writes an info-level message.

2 What is the numeric value of logging.WARNING?

  • 30 Correct answer
  • 20
  • 10
  • 50

Explanation: answer: 30. DEBUG is 10, INFO is 20, ERROR is 40, CRITICAL is 50.

3 Match the log levels concepts

Term Meaning
debug Lowest level
info Info level
warning Warning level
critical Highest level

All lessons in Advanced