-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
64 lines (56 loc) · 1.17 KB
/
logger.js
File metadata and controls
64 lines (56 loc) · 1.17 KB
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
const CALL = Symbol('BaseContextLogger#call');
module.exports = class BaseContextLogger {
/**
* @constructor
* @param {Context} ctx - context instance
* @since 1.0.0
*/
constructor(ctx) {
/**
* @member {Context} BaseContextLogger#ctx
* @since 1.2.0
*/
this.ctx = ctx;
}
[CALL](method, ...args) {
if (!this.ctx.logger) throw new Error(`Use console, please set logger first`);
if (typeof this.ctx.logger[method] === 'function') {
this.ctx.logger[method](...args);
}
}
/**
* @member {Function} BaseContextLogger#debug
* @since 1.2.0
*/
debug(...args) {
this[CALL]('debug', ...args);
}
/**
* @member {Function} BaseContextLogger#info
* @since 1.2.0
*/
info(...args) {
this[CALL]('info', ...args);
}
/**
* @member {Function} BaseContextLogger#warn
* @since 1.2.0
*/
warn(...args) {
this[CALL]('warn', ...args);
}
/**
* @member {Function} BaseContextLogger#error
* @since 1.2.0
*/
error(...args) {
this[CALL]('error', ...args);
}
/**
* @member {Function} BaseContextLogger#log
* @since 1.2.0
*/
log(...args) {
this[CALL]('log', ...args);
}
}