cremalink.local_server_app.logging module

This module provides custom logging setup for the local server application, including an in-memory ring buffer for recent log events and a redaction function for sensitive data.

class cremalink.local_server_app.logging.RingBufferHandler(max_entries: int = 200)[source]

Bases: Handler

A custom logging handler that stores the most recent log records in a fixed-size in-memory deque (a ring buffer).

This is useful for exposing recent server activity via an API endpoint without needing to read from a log file.

emit(record: LogRecord) None[source]

Formats and adds a log record to the ring buffer.

Parameters:

record – The log record to be processed.

get_events() List[Dict][source]

Retrieves a thread-safe copy of all events currently in the buffer.

Returns:

A list of log event dictionaries.

cremalink.local_server_app.logging.create_logger(name: str, ring_size: int) Logger[source]

Creates and configures a logger with the RingBufferHandler.

This function ensures that handlers are not added multiple times to the same logger instance.

Parameters:
  • name – The name of the logger.

  • ring_size – The size of the ring buffer for the handler.

Returns:

A configured logging.Logger instance.

cremalink.local_server_app.logging.redact(details: dict | None) dict[source]

Filters a dictionary, replacing values of sensitive keys with ‘***’.

This is a security measure to prevent secret keys, tokens, and other sensitive data from being exposed in logs.

Parameters:

details – A dictionary that may contain sensitive data.

Returns:

A new dictionary with sensitive values redacted.