llmcompressor.logger
Provides a flexible logging configuration for LLM Compressor.
Using the loguru library, Logger supports console and file logging with options to configure via environment variables or direct function calls.
Environment Variables
LLM_COMPRESSOR_LOG_DISABLED
: Disable logging. Default:False
.LLM_COMPRESSOR_CLEAR_LOGGERS
: Clear existing loggers from loguru. Default:True
.LLM_COMPRESSOR_LOG_LEVEL
: Log level for console logging. Default:None
. Options:DEBUG
,INFO
,WARNING
,ERROR
,CRITICAL
.LLM_COMPRESSOR_LOG_FILE
: Path to the log file for file logging. Default:llm-compressor.log
if log file level set, otherwiseNone
.LLM_COMPRESSOR_LOG_FILE_LEVEL
: Log level for file logging. Default:INFO
if log file is set, otherwiseNone
.
Usage
from llmcompressor import logger, configure_logger, LoggerConfig
# Configure metrics with default settings
configure_logger(
config=LoggerConfig(
disabled=False,
clear_loggers=True,
console_log_level="DEBUG",
log_file=None,
log_file_level=None,
)
)
logger.debug("This is a debug message")
logger.info("This is an info message")
Functions:
-
configure_logger
–Configure the logger for LLM Compressor.
configure_logger
Configure the logger for LLM Compressor.
This function sets up the console and file logging as per the specified or default parameters.
Note: Environment variables take precedence over function parameters.
Parameters:
-
config
Optional[LoggerConfig]
, default:None
) –The configuration for the logger to use.
Source code in llmcompressor/logger.py
support_log_once
Support logging only once using .bind(log_once=True)
logger.bind(log_once=False).info("This will log multiple times")
logger.bind(log_once=False).info("This will log multiple times")
logger.bind(log_once=True).info("This will only log once")
logger.bind(log_once=True).info("This will only log once") # skipped