Logger

Source code: event_collector.logger.py

This module contains logging management functions for event-collector.

The event_collector library uses the structlog loggers from this module to output log entries. All log entries are in JSON format.

Normally, you would not need to interface with this module. However, the loggers are independent of the rest of the event_collector library and can be used as a general JSON-formatted logger in your application to replace the standard logging library.

The log level can be set using the environment variables DEBUG and LOG_LEVEL. If DEBUG is exported as true, yes, or 1, the default log level will be set to “debug.” If DEBUG is not set or is not set to True, then the log level will depend on the exported value of LOG_LEVEL. If LOG_LEVEL is unset, the default log level will be set to the DEFAULT_LOG_LEVEL constant value (“info”).

Example:

DEBUG=true
export DEBUG

# or

LOG_LEVEL="DEBUG"
export LOG_LEVEL

Constants & Types

event_collector.logger.DEFAULT_LOG_LEVEL = 'INFO'

If LOG_LEVEL is not exported as an environment variable, the default log level will be set using this value.

type event_collector.logger.AppLogger = Any | NullLogger

LogRegistry

class event_collector.logger.LogRegistry(default_name: str, log_level: str)

A registry to store all structlog bound loggers identified by name.

add_logger(name: str) AppLogger

Add a logger and bound to name.

get_logger(name: str | None = None) AppLogger

Return a logger bound to name or create a new logger if no logger exists with name as key. This method is called by the get_logger function.

NullLogger

class event_collector.logger.NullLogger

A logger that discards input and produces no output.

Functions

event_collector.logger.set_log_registry(registry: LogRegistry) None

Use registry as the default LogRegistry.

event_collector.logger.get_log_registry() LogRegistry | None

Return the global LogRegistry instance.

event_collector.logger.get_logger(name: str | None = None, is_null: bool = False) AppLogger

Returns a structlog logger. If name is not supplied, logger will output using the default name (defined in LOGGER_NAME).

When first called, will initialize a global LogResgistry instance and create a default struclog logger.

If is_null is True, return a NullLogger.

Example Usage

Output a JSON log entry using the default event_collector logger:

>>> from event_collector.logger import get_logger
>>> log = get_logger()
>>> log.info("example log entry", value="log output")
{"logger":"event-collector","value":"log output","event":"example log entry","level":"info","timestamp":"2026-03-31T02:20:47.335852Z"}