logger

Loguru-based project-specific logger. Consolidates multiprocessing/multithreading logs into a single log file.

Customize its behaviors with these environment variables:
  • logging file path: <PACKAGE_NAME>_LOG_PATH=”/tmp/logs/your_log.log”

  • logging level (for stderr only, default=INFO): <PACKAGE_NAME>_LOG=”TRACE” * If <PACKAGE_NAME>_LOG=”TRACE”, set <PACKAGE_NAME>_FILE_LOG=”TRACE” as well

    unless <PACKAGE_NAME>_FILE_LOG is explicitly set.

  • logging level (for file sink only, default=DEBUG): <PACKAGE_NAME>_FILE_LOG=”TRACE”

Usage:
  • Copy this file into your package (e.g., <package_name>/utils/logger.py)

  • Add the following lines to your __init__.py:

    ```python3 from <package_name>.utils.logger import Logger

    LOGGER = Logger() ```

  • In anywhere of your package, import and use as follows:

    ```python3 from <package_name> import LOGGER

    LOGGER.info(“Hello, world!”) ```

Quick start reference:
  • Logging methods:
    LOGGER.trace(“This is a {} from class {!r} __repr__()”, “trace message”, Class)

    .debug() .info() .success() .warning() .error() .critical() .log(level, “This is {:.4f}”, np.pi)

  • Log ERROR while also capturing exception:
    try:

    except Exception:

    LOGGER.exception(“This is an {}”, “exception message”)

  • Available logging levels = [

    “TRACE” (5), “DEBUG” (10), “INFO” (20), “SUCCESS” (25), “WARNING” (30), “ERROR” (40), “CRITICAL” (50)

    ]

version 0.1.3

Written by Kolin Guo

class real_robot.utils.logger.Logger[source]

Bases: object

A logger for packages that need to use loguru without disrupting the global config. All logs of this package should use an instance of this Logger.

catch(*args, **kwargs)[source]

Delegate the catch context manager to the internal logger.

cleanup()[source]

Remove all handlers added by this library. Restore previous filter functions for stdout/stderr handlers.

static new_filter_fn(record: dict, old_filter_fn: Callable | None) bool[source]

New log filter function for existing handlers