-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlogger.js
54 lines (44 loc) · 1.18 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
// Import libraries.
const chalk = require('chalk')
// Tag list.
var tags = []
tags['blank'] = ' '
tags['continue'] = ': '
tags['info'] = chalk.cyan('[INFO ] ')
tags['warn'] = chalk.yellow('[WARN ] ')
tags['data'] = chalk.green('[DATA ] ')
tags['error'] = chalk.red('[ERROR] ')
tags['fatal'] = chalk.bold.red('[FATAL] ')
tags['state'] = chalk.magenta('[STATE] ')
// Message processor.
function processMessage(message, tag) {
return tags[tag] + message.replace(/\n/g, '\n' + tags['continue'])
}
// Blank log.
exports.blank = function(message) {
console.log(processMessage(message, 'blank'))
}
// Warn log.
exports.warn = function(message) {
console.log(processMessage(message, 'warn'))
}
// Info log.
exports.info = function(message) {
console.log(processMessage(message, 'info'))
}
// Data log.
exports.data = function(message) {
console.log(processMessage(message, 'data'))
}
// Error log.
exports.error = function(message) {
console.log(processMessage(message, 'error'))
}
// Fatal log.
exports.fatal = function(message) {
console.log(processMessage(message, 'fatal'))
}
// State log.
exports.state = function(message) {
console.log(processMessage(message, 'state'))
}