-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogging.js
More file actions
56 lines (52 loc) · 1.4 KB
/
logging.js
File metadata and controls
56 lines (52 loc) · 1.4 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var util = require('util')
var path = require('path')
var winston = require('winston')
var logger = new winston.Logger()
var production = (process.env.NODE_ENV || '').toLowerCase() === 'production'
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, '/application.log'),
handleExceptions: true,
exitOnError: false,
level: 'warn'
})
break
case 'test':
// Don't set up the logger overrides
break
default:
logger.add(winston.transports.Console, {
colorize: true,
timestamp: true,
level: 'info'
})
break
}
function formatArgs (args) {
return [ util.format.apply(util.format, Array.prototype.slice.call(args)) ]
}
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))
}