-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_context_logger.js
64 lines (57 loc) · 1.27 KB
/
base_context_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
const CALL = Symbol('BaseContextLogger#call');
class BaseContextLogger {
/**
* @class
* @param {Context} ctx - context instance
* @param {String} pathName - class path name
* @since 1.0.0
*/
constructor(ctx, pathName) {
/**
* @member {Context} BaseContextLogger#ctx
* @since 1.2.0
*/
this.ctx = ctx;
this.pathName = pathName;
}
[CALL](method, args) {
// add `[${pathName}]` in log
if (this.pathName && typeof args[0] === 'string') {
args[0] = `[${this.pathName}] ${args[0]}`;
}
this.ctx.app.logger[method](...args);
}
/**
* @member {Function} BaseContextLogger#debug
* @param {...any} args - log msg
* @since 1.2.0
*/
debug(...args) {
this[CALL]('debug', args);
}
/**
* @member {Function} BaseContextLogger#info
* @param {...any} args - log msg
* @since 1.2.0
*/
info(...args) {
this[CALL]('info', args);
}
/**
* @member {Function} BaseContextLogger#warn
* @param {...any} args - log msg
* @since 1.2.0
*/
warn(...args) {
this[CALL]('warn', args);
}
/**
* @member {Function} BaseContextLogger#error
* @param {...any} args - log msg
* @since 1.2.0
*/
error(...args) {
this[CALL]('error', args);
}
}
module.exports = BaseContextLogger;