-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathlogger.js
More file actions
63 lines (50 loc) · 1.21 KB
/
logger.js
File metadata and controls
63 lines (50 loc) · 1.21 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
/*!
* This source file is part of the open source project
* ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)
*
* @link https://expressionengine.com/
* @copyright Copyright (c) 2003-2019, EllisLab, Inc. (https://ellislab.com)
* @license https://expressionengine.com/license Licensed under Apache License, Version 2.0
*/
class Logger {
constructor() {
this.reset()
}
reset() {
this._messages = []
this._groups = {}
this.warnCount = 0
}
_addMessage(msg, group) {
if (group) {
if (!this._groups[group]) {
this._groups[group] = []
}
this._groups[group].push(msg)
}
else {
this._messages.push(msg)
}
}
warn(title, msg, group) {
msg = 'WARNING: '.yellow + title.yellow + ' ' + msg
this._addMessage(msg, group)
this.warnCount += 1
}
log(msg, group) {
this._addMessage(msg, group)
}
showMessages() {
for (let [title, items] of Object.entries(this._groups)) {
this._messages.push('\n' + title.bold)
this._messages.push(...items)
}
for (let item of this._messages) {
console.log(item)
}
if (this.warnCount > 0) {
console.log(`\n${this.warnCount} warnings`.yellow)
}
}
}
module.exports = new Logger()