forked from wonderingabout/gtp2ogs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.js
More file actions
39 lines (33 loc) · 1.24 KB
/
console.js
File metadata and controls
39 lines (33 loc) · 1.24 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
// vim: tw=120 softtabstop=4 shiftwidth=4
const fs = require('fs')
const tracer = require('tracer');
const config = require('./config');
const console_fmt = ("{{timestamp}} {{title}} "
+ (config.DEBUG ? "{{file}}:{{line}}{{space}} " : "")
+ "{{message}}");
const console_config = {
format : [ console_fmt ],
dateformat: 'mmm dd HH:MM:ss',
preprocess : function(data){
switch (data.title) {
case 'debug': data.title = ' '; break;
case 'log': data.title = ' '; break;
case 'info': data.title = ' '; break;
case 'warn': data.title = '!'; break;
case 'error': data.title = '!!!!!'; break;
}
if (config.DEBUG) data.space = " ".repeat(Math.max(0, 30 - `${data.file}:${data.line}`.length));
}
};
if (config.logfile) {
const real_console = require('console');
console_config.transport = (data) => {
real_console.log(data.output);
fs.open(config.logfile, 'a', parseInt('0644', 8), function(e, id) {
fs.write(id, data.output+"\n", null, 'utf8', function() {
fs.close(id, () => { });
});
});
}
}
exports.console = tracer.colorConsole(console_config);