Logger Manager
What is LoggerManager?
LoggerManager is a singleton that centralizes logging configuration across all GLLM components.
It initializes the root logger exactly once.
It configures a default handler and formatter based on the
LOG_FORMATenvironment variable.It provides a simple API to get loggers, change formats/levels, and attach custom handlers.
It ensures that child loggers from different parts of the SDK share consistent behavior.
Internally, LoggerManager lives in gllm_core.utils.logger_manager.LoggerManager and is used by components such as Component to obtain properly configured loggers.
Installation
# you can use a Conda environment
pip install --extra-index-url https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/ gllm-core# you can use a Conda environment
pip install --extra-index-url https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/ gllm-core# you can use a Conda environment
FOR /F "tokens=*" %T IN ('gcloud auth print-access-token') DO pip install --extra-index-url "https://oauth2accesstoken:%T@glsdk.gdplabs.id/gen-ai-internal/simple/" "gllm-core"Quickstart
A minimal usage pattern looks like this:
End-to-end behavior:
LoggerManager()creates (or returns) the singleton instance and initializes the root logger on first use.get_logger("my_app")returns a child logger under the shared root.Child loggers reuse the same handlers and formatter as the root logger.
Messages you log are formatted according to the active log mode (text, simple, or JSON).
Logging Modes
LoggerManager supports three logging modes, controlled by the LOG_FORMAT environment variable.
Text mode
Activated when
LOG_FORMAT=text(or whenLOG_FORMATis unset and the default is used).Uses
TextRichHandler, aRichHandlersubclass with per-level colors and[LoggerName]prefixes.Typical for local development where rich, human-readable logs are preferred.
Simple mode
Activated when
LOG_FORMAT=simple.Uses
SimpleRichHandler, a thin wrapper aroundlogging.StreamHandlerthat prints lines such as:Keeps Rich coloring but avoids column-based layout.
JSON mode
Activated when
LOG_FORMAT=json.Uses a standard
StreamHandlerwithAppJSONFormatter.Outputs structured JSON objects, for example:
Best suited for log aggregation systems and machine parsing.
If LOG_FORMAT is not set or contains an unsupported value, LoggerManager falls back to text mode.
Getting Loggers
Use get_logger to obtain either the root logger or a named child logger.
Behavior summary:
Calling
get_logger()with no name returns the root logger.Calling
get_logger(name)returns a child logger with that name.Child loggers:
Have
propagate = Falseto avoid double-logging.Inherit handlers from the root if they do not have handlers yet.
All loggers share the same formatter and respect the same log level set on the root.
Configuring Levels and Formats
LoggerManager exposes methods to adjust logging behavior at runtime.
Set log level for the entire hierarchy
Updates the level of the root logger.
Affects all child loggers unless they override the level individually.
Set a custom log format string
Rebuilds the formatter using the new format string.
Applies the new formatter to all registered handlers.
Preserves the current date format (or default) unless changed separately.
Set a custom date format
Rebuilds the formatter with the new date format.
Keeps the existing message format string.
Updates all handlers to use the new formatter.
Adding Custom Handlers
You can add extra handlers (for example, file or HTTP handlers) while retaining the central formatting logic.
The handler integration process is:
add_handlersets the current formatter on the new handler.The handler is attached to the root logger.
The handler is stored in the manager’s internal handler list.
Future
get_loggercalls ensure child loggers inherit this handler when needed.
This allows you to:
Configure one or more console handlers via log mode.
Attach additional targets (files, sockets, streams) using the same formatting and mode.
Keep all configuration coordinated through a single
LoggerManagerinstance.
JSON Error Payloads
When running in JSON mode, error-related fields are grouped under an error key by AppJSONFormatter.
The formatter keeps only a small set of top-level fields:
timestampnamelevelmessage
The following extra fields, when present, are remapped:
exc_info→error.messagestack_info→error.stacktraceerror_code→error.code
The resulting JSON object only includes an
errorblock if at least one of those fields is non-empty.
Example usage:
In JSON mode this yields a structure similar to:
Rich-Based Handlers
Two handlers leverage Rich for colored, readable logs.
TextRichHandler
Subclasses
rich.logging.RichHandler.Applies a color from
TEXT_COLOR_MAPbased on the log level.Wraps messages with
[color][LoggerName] ...[/]and escapes internal close tags.Best when you want column-based, rich console output.
SimpleRichHandler
Subclasses
logging.StreamHandler.Uses a
rich.console.Consolebound to the handler’s stream.Prints formatted log lines with color, but without the full Rich logging layout.
Useful for simple colored logs that still look like classic log lines.
Both handlers benefit from:
Centralized formatter configuration through
LoggerManager.A shared
TEXT_COLOR_MAPso levels have consistent colors.Escape logic for Rich close tags to avoid breaking markup when messages themselves contain
[/.
Best Practices
Use LoggerManager everywhere
Prefer
LoggerManager().get_logger(__name__)overlogging.getLogger(__name__)directly.This keeps configuration centralized and consistent.
Pick a log mode per environment
LOG_FORMAT=textfor local development.LOG_FORMAT=simplefor minimal, colored logs.LOG_FORMAT=jsonfor production environments with log shipping.
Avoid reconfiguring handlers manually
Let
LoggerManagermanage the root logger and its handlers.Use
add_handler,set_log_format, andset_date_formatinstead of callinglogging.basicConfigin multiple places.
Attach structured error information
Use
extra={"error_code": "..."}when logging errors.Enable
exc_info=Trueto capture stack traces.This pays off especially in JSON mode for observability.
Keep log levels appropriate
Use
DEBUGfor development and detailed troubleshooting.Use
INFOfor standard runtime information.Use
WARNING,ERROR,CRITICALfor exceptional situations.
Last updated