JS API guide for logging

This file provides methods to write logging traces.

How the message is built

Every logging function takes an arbitrary number of parameters (...msg) and concatenates them into a single message. Each one is turned into text according to what it is:

  • Primitive values — strings, numbers, booleans — are written as their text representation.
  • Objects and JSON are serialised with JSON.stringify.
  • Error objects contribute their message plus the context that helps locate the failure.
Tip

Rather than passing several parameters, you can build the message yourself with a template literal and string interpolation:

logger.info(`Operation payload: ${payload}`);

Logger Object

The logger object is the main object for logging functions.

logger.trace(…msg)

Creates TRACE level logging messages. It concatenates msg parameters to compound message to be logged.

Kind: global function
Returns: Void

Param Type Description
…msg any The function takes as parameters a list of elements to be concatenated to generate the string message to be printed.

Example of use:

logger.trace('Operation sent to', host_var, ' and port ', port_var, '. Operation content: ', operation_var);

logger.debug(…msg)

Creates DEBUG level logging messages. It concatenates msg parameters to compound message to be logged.

Kind: global function
Returns: Void

Param Type Description
…msg any The function takes as parameters a list of elements to be concatenated to generate the string message to be printed.

Example of use:

logger.debug('Operation sent to', host_var, ' and port ', port_var, '. Operation content: ', operation_var);

logger.info(…msg)

Creates INFO level logging messages. It concatenates msg parameters to compound message to be logged.

Kind: global function
Returns: Void

Param Type Description
…msg any The function takes as parameters a list of elements to be concatenated to generate the string message to be printed.

Example of use:

logger.info('Operation sent to', host_var, ' and port ', port_var, '. Operation content: ', operation_var);

logger.warn(…msg)

Creates WARN level logging messages. It concatenates msg parameters to compound message to be logged.

Kind: global function
Returns: Void

Param Type Description
…msg any The function takes as parameters a list of elements to be concatenated to generate the string message to be printed.

Example of use:

logger.warn('Operation sent to', host_var, ' and port ', port_var, '. Operation content: ', operation_var);

logger.error(…msg)

Creates ERROR level logging messages. It concatenates msg parameters to compound message to be logged.

Kind: global function
Returns: Void

Param Type Description
…msg any The function takes as parameters a list of elements to be concatenated to generate the string message to be printed.

Example of use:

logger.error('Error connecting to host ', host_var, ' and port ', port_var, '. Stop processing');