-
Notifications
You must be signed in to change notification settings - Fork 8
/
logging.js
executable file
·44 lines (33 loc) · 1.09 KB
/
logging.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
function log () {
try {
let args = Array.from(arguments);
//create options, import from first argument if provided
let options = {};
if (typeof args[0] == 'object') {
options = args.shift();
}
//get bot name
options.botname = global.CONFIG?global.CONFIG.botName:'LOSPEC BOT';
//create log message string
let message =
'\x1b[1m'+ //bold
'\x1b[37m'+ //white
'['+options.botname.toUpperCase()+']'; //bot name
//add module name
if (options.module) message += ' ['+options.module.toUpperCase()+']';
//add error message
if (options.error) message += '\x1b[31m'+' ERROR: '+'\x1b[0m'+options.error.message;
//reset formatting
message+= '\x1b[0m';
//insert text at beginning of array
args.unshift(message);
//log it
console.log.apply(this,args);
//if debug is enabled and an error was passed, log the error stack
if (CONFIG.debug && options.error) console.log(options.error);
} catch (e) {
console.log('error in logging.js',e);
}
}
global.log = log;
/*global Module, CONFIG, client, error, send, react, sendEmoji, pickRandom, messageHasBotPing, isMod */