Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Obss Sahi SahiLogger

From Leeroopedia


Knowledge Sources
Domains Logging, Infrastructure
Last Updated 2026-02-08 12:00 GMT

Overview

Custom logging infrastructure providing color-coded console output and a package-info log level for the SAHI library.

Description

The sahi.logger module defines SAHI's logging system. It introduces a custom log level PKG_INFO_LEVEL (numerically INFO + 5) for displaying package version information with special formatting. The SahiLogger class extends Python's logging.Logger with a pkg_info() method. The SahiLoggerFormatter provides ANSI color-coded output: grey for debug/info, yellow for warnings, red for errors, and cyan/green for package name/version in PKG_INFO messages. A pre-configured module-level logger instance is exported, defaulting to INFO level unless the SAHI_DEBUG environment variable is set.

Usage

Import the logger instance for logging within SAHI modules. Use logger.pkg_info() to emit styled package version messages. Set the SAHI_DEBUG environment variable to enable debug-level output.

Code Reference

Source Location

Signature

PKG_INFO_LEVEL = logging.INFO + 5

class SahiLogger(BaseSahiLogger):
    def pkg_info(self, message: str, *args, **kws) -> None:
        """Log a package info message at PKG_INFO level."""

class SahiLoggerFormatter(logging.Formatter):
    def format(self, record) -> str:
        """Color-coded log formatting with special PKG_INFO handling."""

logger: SahiLogger  # Pre-configured module-level logger named "sahi"

Import

from sahi.logger import logger
# or for custom integrations:
from sahi.logger import SahiLogger, PKG_INFO_LEVEL

I/O Contract

Inputs

Name Type Required Description
SAHI_DEBUG Environment variable No When set, enables DEBUG level logging
message str Yes Log message string

Outputs

Name Type Description
Console output str ANSI color-coded log messages to stderr

Usage Examples

Basic Logging

from sahi.logger import logger

# Standard logging
logger.info("Starting sliced prediction...")
logger.warning("No detections found in slice")
logger.error("Model failed to load")

# Package info logging (special formatting)
logger.pkg_info("sahi version 0.11.36 is loaded")

Enabling Debug Mode

# Enable debug logging via environment variable
export SAHI_DEBUG=1
python my_sahi_script.py

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment