1
|
|
|
/* globals debug, log, info, warn, error */ |
2
|
|
|
/** |
3
|
|
|
* @summary SARAH logger |
4
|
|
|
* @description SarahLogger will automatically add the channel |
5
|
|
|
* in front of the message string |
6
|
|
|
* |
7
|
|
|
* @example <caption>Instantiation</caption> |
8
|
|
|
* const SarahLogger = require('sarah.lib.utils/logger'); |
9
|
|
|
* var logger = new SarahLogger('channel'); |
10
|
|
|
* |
11
|
|
|
* @example <caption>Helper</caption> |
12
|
|
|
* logger.debug(message); |
13
|
|
|
* logger.log(message); |
14
|
|
|
* logger.info(message); |
15
|
|
|
* logger.warn(message); |
16
|
|
|
* logger.error(message); |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @constructor |
21
|
|
|
* |
22
|
|
|
* @param {string} channel |
23
|
|
|
*/ |
24
|
|
|
function SarahLogger(channel) { |
25
|
5 |
|
this.channel = channel; |
26
|
|
|
} |
27
|
|
|
/** |
28
|
|
|
* @public |
29
|
|
|
* @see global debug function |
30
|
|
|
* |
31
|
|
|
* @param {string} msg |
32
|
|
|
*/ |
33
|
1 |
|
SarahLogger.prototype.debug = function(msg) { |
34
|
1 |
|
debug.apply(this, [this.prependChannel(msg)]); |
35
|
|
|
}; |
36
|
|
|
/** |
37
|
|
|
* @public |
38
|
|
|
* @see global log function |
39
|
|
|
* |
40
|
|
|
* @param {string} msg |
41
|
|
|
*/ |
42
|
1 |
|
SarahLogger.prototype.log = function(msg) { |
43
|
1 |
|
log.apply(this, [this.prependChannel(msg)]); |
44
|
|
|
}; |
45
|
|
|
/** |
46
|
|
|
* @public |
47
|
|
|
* @see global info function |
48
|
|
|
* |
49
|
|
|
* @param {string} msg |
50
|
|
|
*/ |
51
|
1 |
|
SarahLogger.prototype.info = function(msg) { |
52
|
1 |
|
info.apply(this, [this.prependChannel(msg)]); |
53
|
|
|
}; |
54
|
|
|
/** |
55
|
|
|
* @public |
56
|
|
|
* @see global warn function |
57
|
|
|
* |
58
|
|
|
* @param {string} msg |
59
|
|
|
*/ |
60
|
1 |
|
SarahLogger.prototype.warn = function(msg) { |
61
|
1 |
|
warn.apply(this, [this.prependChannel(msg)]); |
62
|
|
|
}; |
63
|
|
|
/** |
64
|
|
|
* @public |
65
|
|
|
* @see global error function |
66
|
|
|
* |
67
|
|
|
* @param {string} msg |
68
|
|
|
*/ |
69
|
1 |
|
SarahLogger.prototype.error = function(msg) { |
70
|
1 |
|
error.apply(this, [this.prependChannel(msg)]); |
71
|
|
|
}; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @private |
75
|
|
|
* |
76
|
|
|
* @param {string} msg |
77
|
|
|
* |
78
|
|
|
* @returns {string} |
79
|
|
|
*/ |
80
|
1 |
|
SarahLogger.prototype.prependChannel = function(msg) { |
81
|
5 |
|
return '[' + this.channel + '] ' + msg; |
82
|
|
|
}; |
83
|
|
|
/** |
84
|
|
|
* @private |
85
|
|
|
* @type {string} |
86
|
|
|
*/ |
87
|
1 |
|
SarahLogger.prototype.channel = null; |
88
|
|
|
|
89
|
|
|
/* Export class */ |
90
|
|
|
module.exports = SarahLogger; |
91
|
|
|
|