Skip to content

Logging

setup_logging configures a single logger without touching Python's root logging configuration. It attaches a Rich handler when rich is installed, and falls back to a plain logging.StreamHandler otherwise.

Basic usage

import logging
from pedros import setup_logging, get_logger

setup_logging(level=logging.DEBUG)
logger = get_logger()

logger.debug("This is a debug message.")
logger.info("This is an info message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.critical("This is a critical message.")

If rich is not installed, setup_logging silently falls back to a timestamped, plain-text formatter, no code changes needed.

Options

  • level: numeric level or level name ("DEBUG", "INFO", ...), case-insensitive (default: logging.INFO)
  • logger_name: logger to configure (default: "pedros")
  • add_handler: attach a handler to logger_name; by default, only when neither root logging nor the target logger already has one
  • propagate: propagate records to ancestor loggers; by default, only enabled when the target logger ends up without its own handler (i.e. root logging is doing the handling)

Override either explicitly if you need different behavior:

setup_logging(logger_name="my_package", add_handler=True, propagate=False)

Configuring another logger

By default, setup_logging and get_logger target the pedros logger. Pass logger_name / a name to target any logger, e.g. your own package's, without affecting root logging or other loggers:

setup_logging(logger_name="my_package")
logger = get_logger("my_package")

pedros's own logging

@timed, @safe, @trace, @monitor, and progbar all log through the pedros logger, the same one setup_logging/get_logger target by default. This needs zero setup: the first time any of them logs anything, pedros auto-configures itself at level INFO, so you get formatted output out of the box.

This auto-configuration is deterministic: it always attaches pedros's own handler and disables propagation, regardless of whether it happens before or after your application sets up its own logging. It does not inspect root logging state the way an explicit setup_logging() call does, so the outcome never depends on import/call order. If you want pedros integrated with root logging instead (e.g. so your own handler picks up its records), call setup_logging() yourself before pedros logs anything for the first time — an explicit call always takes precedence and re-derives handler/ propagation state from the current root logging setup.

That default level means @safe's ERROR-level output always shows, but @timed and @trace log at DEBUG and stay silent until you raise pedros's verbosity:

from pedros import setup_logging
import logging

setup_logging(level=logging.DEBUG)

This logger is deliberately kept separate from your own application logger: configuring your own logger (or root logging) never affects pedros's, and vice versa.

If you want to see pedros's own logs (e.g. what @safe caught) alongside yours, pedros is just a stable, ordinary logger name. Attach your own handler to it with the standard library, no pedros-specific API needed:

import logging

logging.getLogger("pedros").addHandler(your_handler)

To silence it instead:

import logging

logging.getLogger("pedros").disabled = True