-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.js
71 lines (63 loc) · 1.85 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
var util = require('util'),
winston = require('winston'),
path = require("path"),
logger = new winston.Logger(),
production = (process.env.NODE_ENV || '').toLowerCase() === 'production',
listid = process.argv[2];
module.exports = {
middleware: function(req, res, next){
console.info(req.method, req.url, res.statusCode);
next();
},
production: production
};
// Override the built-in console methods with winston hooks
switch((process.env.NODE_ENV || '').toLowerCase()){
case 'production':
production = true;
logger.add(winston.transports.File, {
filename: path.join(__dirname, '../logs/', listid + '.log'), // '../logs/' + listid + '.log',
handleExceptions: true,
exitOnError: false,
level: 'info'
});
break;
case 'test':
// Don't set up the logger overrides
return;
default:
logger.add(winston.transports.Console, {
colorize: true,
timestamp: true,
level: 'info'
});
logger.add(winston.transports.File, {
filename: path.join(__dirname, '../logs/', listid + '.log'), // '../logs/' + listid + '.log',
handleExceptions: true,
exitOnError: false,
level: 'info'
});
break;
}
function formatArgs(args){
return [util.format.apply(util.format, Array.prototype.slice.call(args))];
}
console.dir = function(){
logger.info.apply(logger, formatArgs(arguments));
};
console.log = function(){
logger.info.apply(logger, formatArgs(arguments));
};
console.info = function(){
logger.info.apply(logger, formatArgs(arguments));
};
console.warn = function(){
logger.warn.apply(logger, formatArgs(arguments));
};
console.error = function(){
logger.error.apply(logger, formatArgs(arguments));
};
console.debug = function(){
logger.debug.apply(logger, formatArgs(arguments));
};