Implementation:Hpcaitech ColossalAI ColossalQA Logger
| Knowledge Sources | |
|---|---|
| Domains | Logging, Utilities, NLP |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
ColossalQALogger is a singleton-pattern logging class that provides verbosity-controlled logging with info, warning, debug, and error levels for the ColossalQA application.
Description
The ColossalQALogger class wraps Python's standard logging module and enforces a singleton pattern per logger name using a private class-level dictionary. Each logging method (except error) accepts a verbose flag that determines whether the message is actually emitted, providing fine-grained control over debug output. A convenience function get_logger is provided to retrieve or create logger instances by name, defaulting to the name "colossalqa".
Usage
Use ColossalQALogger (via the get_logger function) throughout ColossalQA components when you need controlled logging output. Set verbose=True on individual log calls to enable output during debugging, while keeping production logs clean by default.
Code Reference
Source Location
- Repository: Hpcaitech_ColossalAI
- File: applications/ColossalQA/colossalqa/mylogging.py
- Lines: 1-93
Signature
class ColossalQALogger:
def __init__(self, name):
...
@staticmethod
def get_instance(name: str):
...
def info(self, message: str, verbose: bool = False) -> None:
...
def warning(self, message: str, verbose: bool = False) -> None:
...
def debug(self, message: str, verbose: bool = False) -> None:
...
def error(self, message: str) -> None:
...
def get_logger(name: str = None, level=logging.INFO) -> ColossalQALogger:
...
Import
from colossalqa.mylogging import get_logger, ColossalQALogger
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes (for __init__) | The name for the logger instance; must be unique across all instances |
| message | str | Yes | The log message string to emit |
| verbose | bool | No | Controls whether info, warning, and debug messages are actually logged (default: False) |
Outputs
| Name | Type | Description |
|---|---|---|
| get_instance return | ColossalQALogger | The singleton logger instance for the given name |
| get_logger return | ColossalQALogger | A logger instance, creating one if it does not exist (default name: "colossalqa") |
Usage Examples
from colossalqa.mylogging import get_logger
# Get the default ColossalQA logger
logger = get_logger()
# Log with verbose control
logger.info("Loading data...", verbose=True) # Will print
logger.info("Loading data...", verbose=False) # Will not print
# Log warnings and debug messages
logger.warning("Deprecated feature used", verbose=True)
logger.debug("Variable x = 42", verbose=True)
# Error messages are always logged regardless of verbose flag
logger.error("Failed to connect to database")
# Get a named logger
custom_logger = get_logger(name="my_module")
custom_logger.info("Module initialized", verbose=True)