Moogsoft Docs

Logger

The Logger module sets the log level in moog_farmd, allowing log messages to be written to the common moog_farmd log file.

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

Note

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

logger.debug

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

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

logger.warning()

Sends a warning log message (a higher severity level). For example, this can be used to log behaviour 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

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 moog_farmd 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