Moogsoft Docs

Logger

  • logger.debug()

  • logger.info()

  • logger.warning()

  • logger.fatal()

Warning

The Logger module was deprecated for the release of Moogsoft AIOps 7.1.0. See Configure Logging for details on the the new Logger.

The Logger module sets the log level in Moogfarmd, allowing log messages to be written to the common Moogfarmd log file. SeeConfigure Loggingfor information on configuring logging.

For example, when you write a Moobot, you can use the Logger for debug. Writing a log message to a log file is an IO operation, and comes with execution time cost. When developing the Moobot it can be helpful to have a number of logging statements. Once the Moobot is operational, however, you should keep log messaging to a minimum.

The Logger module is available to load into any standard Moobot.

To use, at the top of a Moobot js file, define a new global object logger to load the Logger module:

var logger = MooBot.loadModule('Logger');

Reference Guide

The logmessage argument used in the Logger module is a single string.

Multiple arguments are possible using concatenation. See Examples.

Note

printf based Logger functions have been deprecated in favour of the 'single string argument' version. For more information click here.

logger.debug()

Sends a debug log message (the lowest severity level). For example, this can be used for logging detailed troubleshooting information (not for production). See Examples.

Request Argument

Name

Type

Description

logmessage

String

A single string of valid JavaScript variables or objects, used to form a log message.

Return Parameter

Void - no value returned.

logger.info()

Sends an information log message (the intermediate severity level). For example, this can be used to log the changing of a setting. See Examples.

Request Argument

Name

Type

Description

logmessage

String

A single string of valid JavaScript variables or objects, used to form a log message.

Return Parameter

Void - no value returned.

logger.warning()

Sends a warning log message (a higher severity level). For example, this can be used to log behavior which impacts normal operation of the system. See Examples.

Request Argument

Name

Type

Description

logmessage

String

A single string of valid JavaScript variables or objects, used to form a log message.

Return Parameter

Void - no value returned.

logger.fatal()

Sends a fatal log message (the highest severity setting). For example this can be used to log extreme circumstances, such as an unrecoverable failure that caused Moogfarmd to exit. See Examples.

Request Argument

Name

Type

Description

logmessage

String

A single string of valid JavaScript variables or objects, used to form a log message.

Return Parameter

Void - no value returned.

Examples

All the above methods work in the same way, with each sending a log message of a different severity level.

{
   var dispText= "Reset";
   var dispNum= 2;
   var aReal= 3.141593;
   var aString= "CPU@ >90%";
   var intHigh= 4;
   var intHighest= 5;

logger.debug("A debug message");

logger.info("Counter: "+ dispText);

logger.info("Severity low. Level: "+ dispNum + ". ...Pi = "+ aReal);

logger.warning("Warning: "+ aString);

logger.warning("Severity high. Level: "+ intHigh);

logger.fatal("Severity exceeds "+ intHighest + "! Restart required");
}

The above six logger arguments give the following six corresponding log messages:

DEBUG:... ...A debug message

INFO :... ...Counter: Reset

INFO :... ...Severity low. Level: 2. ...Pi = 3.141593

WARN :... ...Warning: CPU@ >90%

WARN :... ...Severity high. Level: 4

FATAL:... ...Severity exceeds 5! Restart required