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:
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.
Param | Type | Description |
---|---|---|
levels | LogLevel[] | 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).
Param | Type | Description |
---|---|---|
tag | number | Tag represented by a positive integer. |
msg | unknown[] | 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).
Param | Type | Description |
---|---|---|
tag | number | Tag represented by a positive integer. |
msg | unknown[] | 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).
Param | Type | Description |
---|---|---|
tag | number | Tag represented by a positive integer. |
msg | unknown[] | A spread of message to log. |