-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
51 lines (44 loc) · 1.18 KB
/
logger.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
const winston = require("winston")
, extend = require('extend')
, dbURL = "mongodb://localhost:27017/LoggerDb"
require('winston-mongodb').MongoDB
var defaults = {
transports: {
file: {
level: 'info',
colorize: false,
timestamp: true,
json: true,
filename: __base + "/log/dev.log",
maxsize: 5242880,
maxFile: 10,
logstash: false,
tailable: true
},
console: {
level: 'debug',
colorize: true,
json: false,
handleExceptions: true,
humanReadableUnhandledException: true
},
MongoDB: {
db : dbURL,
collection: 'logs'
}
}
}
function optionsToWinston(options){
var transportObjects = []
Object.keys(options.transports).forEach(function(key){
var transportName = [key[0].toUpperCase() + key.slice(1)]
if(winston.transports[transportName])
transportObjects.push(new winston.transports[transportName](options.transports[key]))
})
return extend(options, {transports: transportObjects})
}
module.exports = ( function(options) {
options = options || {}
extend(true, defaults, options)
return new winston.Logger(optionsToWinston(defaults))
})