Logger

Logger that captures and formats log messages.

Implements: ILogger, IReconfigurable, IReferenceable

Description

The Logger class allows you to create a logger that captures and formats logs messages.

Important points

  • Child classes take the captured messages and write them to their specific destinations.

Configuration parameters

Parameters to pass to the configure method for component configuration:

  • level: maximum log level to capture
  • source: source (context) name

References

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

Constructors

Creates a new instance of the logger.

Logger()

Fields

_level

Maximum log level to capture

_level: LogLevel = LogLevel.Info

source

source (context) name

source: String?

Instance methods

composeError

Composes an human-readable error description

String composeError(Exception error)

  • error: Exception - an error to format.
  • returns: String - a human-redable error description.

configure

Configures component by passing configuration parameters.

@override

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

debug

Logs high-level debug information for troubleshooting.

@override

void debug(IContext? context, String message, [List? args])

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: String - a human-readable message to log.
  • args: List? - arguments to parameterize the message.

error

Logs recoverable application error.

@override

void error(IContext? context, Exception? error, String message, [List? args])

  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception? - an error object associated with this message.
  • message: String - a human-readable message to log.
  • args: List? - arguments to parameterize the message.

fatal

Logs fatal (unrecoverable) message that caused the process to crash.

@override

void fatal(IContext? context, Exception? error, String message, [List? args])

  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception? - an error object associated with this message.
  • message: String - a human-readable message to log.
  • args: List? - arguments to parameterize the message.

_formatAndWrite

Formats the log message and writes it to the logger destination.

void _formatAndWrite(LogLevel level, IContext? context, Exception error, String message, List args)

  • level: LogLevel - a log level.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - an error object associated with this message.
  • message: String - a human-readable message to log.
  • args: List - arguments to parameterize the message.

getLevel

Gets the maximum log level. Messages with higher log level are filtered out.

@override

LogLevel getLevel()

  • returns: LogLevel - the maximum log level.

getSource

Gets the source (context) name.

String? getSource()

  • returns: String? - the source (context) name.

info

Logs an important information message

@override

void info(IContext? context, String message, [List? args])

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: String - a human-readable message to log.
  • args: List? - arguments to parameterize the message.

log

Logs a message at a specified log level.

@override

void log(LogLevel level, String? context, Exception? error, String message, [List? args])

  • level: LogLevel - a log level.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception? - an error object associated with this message.
  • message: String - a human-readable message to log.
  • args: List? - arguments to parameterize the message.

setLevel

Set the maximum log level.

@override

void setLevel(LogLevel value)

  • level: LogLevel - a new maximum log level.

trace

Logs low-level debug information for troubleshooting.

@override

void trace(IContext? context, String message, [List? args])

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: String - a human-readable message to log.
  • args: List? - arguments to parameterize the message.

warn

Logs a warning that may or may not have a negative impact.

@override

void warn(IContext? context, String message, [List? args])

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: String - a human-readable message to log.
  • args: List? - arguments to parameterize the message.

Abstract methods

write

Writes a log message to the logger destination.

void write(LogLevel level, IContext? context, Exception? error, String message)

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

See also