ElasticSearchLogger class

Logger that dumps execution logs to ElasticSearch service.

ElasticSearch is a popular search index. It is often used to store and index execution logs by itself or as a part of ELK (ElasticSearch - Logstash - Kibana) stack.

Authentication is not supported in this version.

Configuration parameters

  • level: maximum log level to capture
  • source: source (context) name
  • connection(s):
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • protocol: connection protocol: http or https
    • host: host name or IP address
    • port: port number
    • uri: resource URI or connection string with all parameters in it
  • 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)
    • index: ElasticSearch index name (default: 'log')
    • date_format The date format to use when creating the index name. Eg. log-yyyyMMdd (default: 'yyyyMMdd'). See DateFormat
    • daily: true to create a new index every day by adding date suffix to the index name (default: false)
    • reconnect: reconnect timeout in milliseconds (default: 60 sec)
    • timeout: invocation timeout in milliseconds (default: 30 sec)
    • max_retries: maximum number of retries (default: 3)
    • index_message: true to enable indexing for message object (default: false)
    • include_type_name: Will create using a "typed" index compatible with ElasticSearch 6.x (default: false)

References

  • *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source
  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection

Example

var logger = ElasticSearchLogger();
logger.configure(ConfigParams.fromTuples([
    'connection.protocol', 'http',
    'connection.host', 'localhost',
    'connection.port', 9200
]));

await logger.open('123')
    ...

logger.error('123', ex, 'Error occured: %s', ex.message);
logger.debug('123', 'Everything is OK.');

Constructors

ElasticSearchLogger()
Creates a new instance of the logger.

Properties

cache List<LogMessage>
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
interval int
getter/setter pairinherited
lastDumpTime int
getter/setter pairinherited
maxCacheSize int
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
source String?
getter/setter pairinherited
updated bool
getter/setter pairinherited

Methods

clear() → void
Clears (removes) all cached log messages.
inherited
close(String? correlationId) Future
Closes component and frees used resources.
composeError(Exception error) String
Composes an human-readable error description
inherited
configure(ConfigParams config) → void
Configures component by passing configuration parameters.
debug(String? correlationId, String message, [List? args]) → void
Logs a high-level debug information for troubleshooting.
inherited
dump() → void
Dumps (writes) the currently cached log messages.
inherited
error(String? correlationId, Exception? error, String message, [List? args]) → void
Logs recoverable application error.
inherited
fatal(String? correlationId, Exception? error, String message, [List? args]) → void
Logs fatal (unrecoverable) message that caused the process to crash.
inherited
getLevel() → LogLevel
Gets the maximum log level. Messages with higher log level are filtered out.
inherited
getLogItem() Map<String, dynamic>
getSource() String?
Gets the source (context) name.
inherited
info(String? correlationId, String message, [List? args]) → void
Logs an important information message
inherited
isOpen() bool
Checks if the component is opened.
log(LogLevel level, String? correlationId, Exception? error, String message, [List? args]) → void
Logs a message at specified log level.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(String? correlationId) Future
Opens the component.
save(List<LogMessage> messages) Future
Saves log messages from the cache.
setLevel(LogLevel value) → void
Set the maximum log level.
inherited
setReferences(IReferences references) → void
Sets references to dependent components.
setSource(String value) → void
Sets the source (context) name.
inherited
toString() String
A string representation of this object.
inherited
trace(String? correlationId, String message, [List? args]) → void
Logs a low-level debug information for troubleshooting.
inherited
update() → void
Makes message cache as updated and dumps it when timeout expires.
inherited
warn(String? correlationId, String message, [List? args]) → void
Logs a warning that may or may not have a negative impact.
inherited
write(LogLevel level, String? correlationId, Exception? error, String message) → void
Writes a log message to the logger destination.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited