CachedLogger

Logger that caches captured log messages in memory and periodically dumps them.

Implements: Logger

Description

The CachedLogger class allows you to create a logger that caches captured log messages in memory and periodically dumps them.

Important points

  • Child classes implement saving cached messages to their specified destinations.

Configuration parameters

  • level: maximum log level to capture
  • source: source (context) name
  • options:
    • interval: interval in milliseconds to save log messages (default: 10 seconds)
    • max_cache_size: maximum number of messages stored in this cache (default: 100)

References

  • *:context-info:*:*:1.0 - (optional) ContextInfo to detect the context id and specify counters source

Fields

_cache

List containing log messages.

_cache: List[LogMessage] = []

_updated

Boolean variable indicating whether there has been an update or not.

_updated = False

_interval

Interval in milliseconds to save log messages (default: 10 seconds)

_interval = 10000

_last_dump_time

Time of the last dump

_last_dump_time: float

_max_cache_size

Maximum number of messages stored in the cache (default: 100)

_max_cache_size: int = 100

Instance methods

clear

Clears (removes) all cached log messages.

clear()

configure

Configures component by passing configuration parameters.

configure(config: ConfigParams)

  • config: ConfigParams - configuration parameters to be set.

dump

Dumps (writes) the currently cached log messages.

dump()

_update

Sets message cache as updated and dumps it when timeout expires.

_update()

_write

Writes a log message to the logger destination.

_write(level: LogLevel, context: Optional[IContext], ex: Exception, message: str)

  • level: LogLevel - a log level.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • ex: Exception - an error object associated with this message.
  • message: str - a human-readable message to log.

_save

Saves log messages from the cache.

_save(messages: List[LogMessage])

  • messages: List[LogMessage] - a list with log messages

See also