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.OperationalConsoleHandler(stream=None)[source]

Bases: StreamHandler

Render operational details to the standalone server’s console.

emit(record: LogRecord) → None[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

class cremalink.local_server_app.logging.RingBufferHandler(max_entries: int = 200, forward_logger: Logger | None = None, diagnostic_sensitive_values: tuple[str | None, ...] = (), operational_sensitive_values: tuple[str | None, ...] = ())[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, *, forward_logger: Logger | None = None, diagnostic_sensitive_values: tuple[str | None, ...] = (), operational_sensitive_values: tuple[str | None, ...] = (), console: bool = False) → 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.log_event(logger: Logger, event: str, details: dict | None = None, *, diagnostic_sensitive_values: tuple[str | None, ...] = (), operational_sensitive_values: tuple[str | None, ...] = (), level: int = 20, telemetry: bool = False) → None[source]

Emit one record with separate operational and diagnostic details.

cremalink.local_server_app.logging.redact(details: dict | None, sensitive_values: tuple[str | 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.

cremalink.local_server_app.logging.redact_operational(details: dict | None, sensitive_values: tuple[str | None, ...] = ()) → dict[source]

Redact credentials while permitting approved troubleshooting values.

cremalink.local_server_app.logging.redact_telemetry_operational(details: dict | None, sensitive_values: tuple[str | None, ...] = ()) → dict[source]

Permit top-level device identifiers without unredacting nested telemetry.