Skip to content

01_Logging

Thomas Byr edited this page May 25, 2026 · 2 revisions

Rich logging

  1. Initialize globally
  2. Mute loggers

Initialize globally

Initializing loggers is done automatically when using the cli module and registering a command with the @cli.cmd decorator. If you don't use the cli module, you can initialize the loggers globally with the init_handler function. If you specify a log level, it will be used as the default minimum log level for all loggers. Otherwise, the default log level is logging.INFO. The second argument will create a rotating file handler that saves logs to the specified path. The file handler will rotate when the log file reaches 10MB, and it will keep up to 5 backup files.

import logging
from nob.logging import init_handler

init_handler(logging.DEBUG)
logging.info("Hello world")

Mute loggers

You can mute loggers by their name. Call mute_loggers after the logger is initialized and configured properly. Pass as many logger names as you want.

Important

Make sure to call mute_loggers with the name of the logger (which may differ from the module name) before it is used for the first time.

import my_noisy_lib
from nob.logging import mute_loggers

mute_loggers("my_noisy_lib")

Clone this wiki locally