forked from auth0/ad-ldap-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventlog.js
57 lines (47 loc) · 1.31 KB
/
eventlog.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
55
56
57
var winston = require('winston');
var rotator = require('stream-rotate');
winston.remove(winston.transports.Console);
if (process.platform === 'win32') {
var log_stream = rotator({
path: __dirname,
name: 'logs',
size: '1m',
retention: 5
});
winston.add(winston.transports.File, {
stream: log_stream,
level: "debug",
json: false,
handleExceptions: true
});
}
var old_log = console.log;
var old_error = console.error;
var old_warn = console.warn;
var util = require('util');
function add_timestamp (args) {
var timestamp = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
var result = Array.prototype.slice.call(args);
result[0] = '[' + timestamp + '] ' + result[0];
return result;
}
function winston_wrap (fn, winston_fn) {
return function() {
var args = add_timestamp(arguments);
var message = util.format.apply(util, args).stripColors;
if (!message) return;
winston_fn(message);
fn.apply(console, args);
};
}
console.restore = function() {
console.log = old_log;
console.error = old_error;
console.warn = old_warn;
};
console.inject = function() {
console.log = winston_wrap(old_log, winston.debug);
console.error = winston_wrap(old_error, winston.error);
console.warn = winston_wrap(old_warn, winston.warn);
};
console.inject();