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

Fields

_level

Maximum log level to capture

LogLevel _level = LogLevel.Info

_source

source (context) name

String _source = null

Instance methods

compose_error

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.

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

debug

Logs high-level debug information for troubleshooting.

void debug(IContext context, String message, Object… args)

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

error

Logs recoverable application error.

void error(IContext context, Exception error, String message, Object… 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: Any - arguments to parameterize the message.
  • kwargs: Any - arguments to parameterize the message.

fatal

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

void fatal(IContext context, String message, Object… args)

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

formatAndWrite

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

formatAndWrite(LogLevel level, IContext context, Exception error, String message, Object[] args)

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

get_level

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

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

info(context: Optional[IContext], message: str, *args: Any, **kwargs: Any) void info(IContext context, String message, Object… args)

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

log

Logs a message at a specified log level.

void log(LogLevel level, IContext context, Exception error, String message, Object… 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: Object - arguments to parameterize the message.

setLevel

Sets the maximum log level.

void setLevel(LogLevel value)

  • level: LogLevel - a new maximum log level.

trace

Logs a low-level debug information for troubleshooting.

void trace(IContext context, String message, Object… args)

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

warn

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

warn(context: Optional[IContext], message: str, *args: Any, **kwargs: Any) void warn(IContext context, String message, Object… args)

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

Abstract methods

_write

Writes a log message to the logger destination.

abstractmethod 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