logger.js
1.2 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
57
58
59
60
61
62
// # boot - logger
var _ = require('underscore')
var mergeDefaults = require('merge-defaults')
var winston = require('winston')
var winstonMongoDB = require('winston-mongodb')
var winstonHipchat = require('winston-hipchat')
exports = module.exports = function(settings) {
if (!_.isObject(settings.logger))
throw new Error('Settings did not have a `logger` object')
if (!_.isObject(settings.output))
throw new Error('Settings did not have a `output` object')
var transports = []
if (settings.logger['console'])
transports.push(
new winston.transports.Console(
settings.output
)
)
if (settings.logger.mongo)
transports.push(
new winstonMongoDB.MongoDB(
mergeDefaults(
settings.output,
settings.mongo
)
)
)
if (settings.logger.file)
transports.push(
new winston.transports.File(
mergeDefaults(
settings.output,
settings.logger.file
)
)
)
if (settings.logger.hipchat)
transports.push(
new winstonHipchat.Hipchat(settings.hipchat)
)
var logger = new winston.Logger({
transports: transports
})
return logger
}
exports['@singleton'] = true
exports['@require'] = [ 'igloo/settings' ]