Logger

The logger offers a configuration section to handle application log messages filtered by a level and using various defined appenders. It is commonly used for debugging purpose as seen in common JavaScript frameworks.

Configuration

Any supported appender must be declared in the application configuration:

{
    "default": {
        "Logger": {
            "ConsoleAppender": {
                "level": "info"
            },
            "FileAppender": {
                "level": "info"
            }
        }
    }
}

This configuration structure is setting various levels per appender which are used as threshold filters.

Available appenders

An appender is a way to change where the log are output. Two types of appenders exists:

  • Console: where this specific appender is outputting those log messages onto JavaScript’s console output window.
  • File: used as an appender that is writing log messages into a defined local file (as seen under NodeJS vendor).

It is possible to create your own appenders in order to redirect your log to websocket or http for example.

Logging levels

There are various ways to log messages by filtering them, in order of fatality:

  • debug level: holding code “tracing” messages which are more helpful as logging application diagnostics for developers.
  • info level: which are showing message including useful information to log (like service lifecycle status, configurations, …),
  • warn level: where warning messages are happening on anything that can potentially cause application oddities.
  • error level: meaning any error message which is fatal to the ongoing operation inside current application or running service.

This assumes that those levels are ordered by values as following: ERROR > WARN > INFO > DEBUG.

logger_levels

In a more graphic way, here is how the selection rule works. In the following table, the vertical header shows the level of the logging request while the horizontal header shows effective level of the logger. The intersection of rows (level request) and columns (effective level) is the boolean value resulting from the basic selection rule.

levelDEBUGINFOWARNERROROFF
DEBUGβœ”βœ˜βœ˜βœ˜βœ˜
INFOβœ”βœ”βœ˜βœ˜βœ˜
WARNβœ”βœ”βœ”βœ˜βœ˜
ERRORβœ”βœ”βœ”βœ”βœ˜

API Reference

This application component is part of Dana’s core vendor which includes a JSdoc description. See the components Logger, AbstractConsoleAppender, AbstractFileAppender under the category utils/log of this core API.