Logger that caches captured log messages in memory and periodically dumps them.
Extends: 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
Instance methods
clear
Clears (removes) all cached log messages.
void clear()
configure
Configures component by passing configuration parameters.
public
void configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
dump
Dumps (writes) the currently cached log messages.
public
void dump()
update
Sets message cache as updated and dumps it when timeout expires.
protected
void update()
write
Writes a log message to the logger destination.
protected
void write(LogLevel level, IContext context, Exception ex, String message)
- level: LogLevel - a log level.
- context: IContext - (optional) a context to trace execution through call chain.
- ex: Exception - an exception object associated with this message.
- message: string - a human-readable message to log.
Abstract methods
save
Saves log messages from the cache.
protected abstract
void save(List<LogMessage> messages) throws InvocationException
- messages: LogMessage[] - a list with log messages