Implementation:LMCache LMCache Logging
| Knowledge Sources | |
|---|---|
| Domains | Logging, Observability |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Provides a custom color-coded logging framework for LMCache with configurable log levels via environment variables.
Description
This module defines a CustomFormatter that applies ANSI color codes to log messages based on severity level: grey for DEBUG, green for INFO, yellow for WARNING, red for ERROR, and bold red for CRITICAL. Each log line includes a timestamp, the "LMCache" prefix, the log level, the message, and an italicized source location (filename, line number, logger name). The init_logger function creates isolated loggers with no propagation to parent loggers. Log level is controlled by the LMCACHE_LOG_LEVEL environment variable, defaulting to INFO.
Usage
Call init_logger(__name__) at the top of any LMCache module to obtain a properly configured logger instance. Set the LMCACHE_LOG_LEVEL environment variable to DEBUG, INFO, WARNING, ERROR, or CRITICAL to control verbosity.
Code Reference
Source Location
- Repository: LMCache
- File: lmcache/logging.py
- Lines: 1-96
Signature
def build_format(color: str) -> str: ...
class CustomFormatter(logging.Formatter):
def format(self, record) -> str: ...
def get_log_level() -> int: ...
def init_logger(name: str) -> Logger: ...
Import
from lmcache.logging import init_logger
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | Logger name, typically __name__ of the calling module |
| LMCACHE_LOG_LEVEL | env var | No | Environment variable to set log level (default: INFO) |
Outputs
| Name | Type | Description |
|---|---|---|
| logger | logging.Logger | Configured logger with color-coded console output and no parent propagation |
Usage Examples
from lmcache.logging import init_logger
logger = init_logger(__name__)
logger.debug("Detailed debugging information")
logger.info("Cache engine initialized successfully")
logger.warning("Cache miss rate exceeding threshold")
logger.error("Failed to connect to remote storage")