Logger

Logging wrapper.

This is used to allow turning on/off: - console.log - console.warn - console.error

Usage 

 1import {Logger, LogLevel, LogTag} from '@wonderlandengine/api';
 2
 3// Create a logger with only the "error" and "warn" levels activated
 4const logger = new Logger(LogLevel.Warn, LogLevel.Error);
 5
 6// Only the "error" and "warn" levels are activated,
 7// this message isn't logged.
 8logger.info(LogTag.Component, 'This message is shushed')
 9
10// Prints 'Hello Error!'
11logger.error(LogTag.Component, 'Hello Error!');
12
13// Prints 'Hello Warning!'
14logger.warn(LogTag.Component, 'Hello Warning!');

The log levels can be changed at anytime using the BitSet api:

1// Enable the "info" level
2logger.levels.enable(LogLevel.Info);
3* // Disable the "warn" level
4logger.levels.disable(LogLevel.Warn);

Tags 

In addition, the logger supports tagging messages:

 1import {Logger, LogLevel, LogTag} from '@wonderlandengine/api';
 2
 3const logger = new Logger(LogLevel.Info);
 4
 5logger.tags.disableAll();
 6
 7// All tags are off, this message isn't logged
 8logger.info(LogTag.Component, 'This message is shushed');
 9
10logger.tags.enable(LogTag.Component);
11logger.info(LogTag.Component, 'Hello World!') // Prints 'Hello World!'

The tagging system gives another layer of control to enable / disable some specific logs.

.constructor(…levels: LogLevel[][]) ⇒ Logger 

Create a new logger instance.

ParamTypeDescription
levelsLogLevel[]Default set of levels to enable.

.error(tag: number, …msg: unknown[][]) ⇒ Logger 

Log the message(s) using console.error.

Returns: Reference to self (for method chaining).

ParamTypeDescription
tagnumberTag represented by a positive integer.
msgunknown[]A spread of message to log.

.info(tag: number, …msg: unknown[][]) ⇒ Logger 

Log the message(s) using console.log.

Returns: Reference to self (for method chaining).

ParamTypeDescription
tagnumberTag represented by a positive integer.
msgunknown[]A spread of message to log.

.warn(tag: number, …msg: unknown[][]) ⇒ Logger 

Log the message(s) using console.warn.

Returns: Reference to self (for method chaining).

ParamTypeDescription
tagnumberTag represented by a positive integer.
msgunknown[]A spread of message to log.