Logger

Logger

Logger class. Provides logging functionality.

Output options provided by the class as a static enumeration

Constructor

new Logger()

Source:
Requires:

Requires

Methods

getInstanceId() → {string}

Source:

Provides a unique identifier for the current class instance

Returns:

A unique identifier for the current instance

Type
string

log(logName, data, outputsopt, fileExtentionopt, prefixEntryWithTimestampopt)

Source:

Logs data to selected Outputs

When using the same class instance, FILE outputs append to the previous file when the same logName is reused

Example
// call library
const rootRequire = require('rpcm-root-require');
const Logger = rootRequire('/platform-helpers/logger');
const logger = new Logger();

// creates a file "logName.log" in the logs folder
logger.log("logName", "The quick brown fox jumps over the lazy dog!");

// creates a file "logName.log" in the logs folder
// content: {{timestamp}}: The quick brown fox jumps over the lazy dog!
logger.log("logName", "The quick brown fox jumps over the lazy dog!", Logger.Outputs.FILE, null);

// creates a file "jsonDataLogName.json" in the logs folder
// content:
// {
//   "1": "a"
// }
logger.log("jsonDataLogName", '{"1":"a"}', Logger.Outputs.FILE, 'json', false);
Parameters:
Name Type Attributes Default Description
logName string

Log name. Generates the aggregation name. E.G.: file name composed of current timestamp and logName.

data string

Data to log. Possible types: string, json object

outputs Array.<Outputs> | string.<Outputs> <optional>
Logger.Outputs.CONSOLE

An array with expected outputs. Valid array values from class enumeration {Outputs}. Alternatively also accepts one single enumeration value.

fileExtention string <optional>
'log'

Provide a specific extension for the file. Affects FILE 'Outputs' only.

prefixEntryWithTimestamp boolean <optional>
true

Specify if the data to log in the file should be prefixed with a timestamp. This is usefull when logging multiple entries to the same file. Affects FILE 'Outputs' only.

Type Definitions

Outputs

Source:
Properties:
Name Type Description
CONSOLE string

Used to tell the logger to print to the console

FILE string

Used to tell the logger to buffer the data to a log file. Log files location {{project-root}}/logger

Enumeration with valid output destinations

Type:
  • Outputs