-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
65 lines (56 loc) · 1.83 KB
/
logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @callback LoggerCallback
* @param {String} state - Always a "log" string.
* @param {String} severity - The severity level of the log message, either "error", "warn", "info", or "debug".
* @param {Array} args - The log message arguments, this can be a mix of types.
*/
/**
* A logging interface class that exposes friendly log methods that pass information to a configured callback.
*/
class Logger {
/**
* Creates a new `Logger` instance.
* @param {LoggerCallback} callback - The logging callback asynchronously called when a log method call is made.
*/
constructor(callback) {
/** @type {LoggerCallback} */
this.callback = callback || null;
}
/**
* Writes a debug-severity log message. This is the lowest severity.
* @param {...any} args - Any object values to be logged.
*/
async debug(...args) {
if (this.callback) {
await this.callback('log', 'debug', args);
}
}
/**
* Writes an information-severity log message. This is the second-to-lowest severity.
* @param {...any} args - Any object values to be logged.
*/
async info(...args) {
if (this.callback) {
await this.callback('log', 'info', args);
}
}
/**
* Writes a warning-severity log message. This is the second-to-highest severity.
* @param {...any} args - Any object values to be logged.
*/
async warn(...args) {
if (this.callback) {
await this.callback('log', 'warn', args);
}
}
/**
* Writes a error-severity log message. This is the highest severity.
* @param {...any} args - Any object values to be logged.
*/
async error(...args) {
if (this.callback) {
await this.callback('log', 'error', args);
}
}
}
export default Logger;