正在显示
2 个修改的文件
包含
67 行增加
和
10 行删除
... | ... | @@ -12,13 +12,27 @@ exports = module.exports = function() { |
12 | 12 | cookieParser: '', |
13 | 13 | mongo: { |
14 | 14 | host: 'localhost', |
15 | - port: '27017', | |
16 | - opts: {} | |
15 | + port: 27017, | |
16 | + opts: {}, | |
17 | + // faster - don't perform 2nd request to verify | |
18 | + // log message was received/saved | |
19 | + safe: false | |
17 | 20 | }, |
18 | 21 | redis: { |
19 | 22 | host: 'localhost', |
20 | 23 | port: 6379, |
21 | 24 | maxAge: 24 * 60 * 60 * 1000 |
25 | + }, | |
26 | + output: { | |
27 | + handleExceptions: true, | |
28 | + colorize: true, | |
29 | + prettyPrint: true, | |
30 | + level: 'info' | |
31 | + }, | |
32 | + logger: { | |
33 | + 'console': true, | |
34 | + mongo: false, | |
35 | + file: false, | |
22 | 36 | } |
23 | 37 | }, |
24 | 38 | development: { |
... | ... | @@ -27,7 +41,7 @@ exports = module.exports = function() { |
27 | 41 | port: 3000, |
28 | 42 | }, |
29 | 43 | mongo: { |
30 | - dbname: 'igloo-development', | |
44 | + db: 'igloo-development', | |
31 | 45 | }, |
32 | 46 | redis: { |
33 | 47 | prefix: 'igloo-development' |
... | ... | @@ -39,10 +53,26 @@ exports = module.exports = function() { |
39 | 53 | port: 80, |
40 | 54 | }, |
41 | 55 | mongo: { |
42 | - dbname: 'igloo-production', | |
56 | + db: 'igloo-production', | |
43 | 57 | }, |
44 | 58 | redis: { |
45 | 59 | prefix: 'igloo-production' |
60 | + }, | |
61 | + output: { | |
62 | + handleExceptions: false, | |
63 | + prettyPrint: false, | |
64 | + colorize: false | |
65 | + }, | |
66 | + logger: { | |
67 | + 'console': false, | |
68 | + mongo: true, | |
69 | + // <https://github.com/flatiron/winston#file-transport> | |
70 | + file: { | |
71 | + filename: '/var/log/igloo.log', | |
72 | + // TODO: maxsize | |
73 | + // TODO: maxFiles | |
74 | + timestamp: true | |
75 | + } | |
46 | 76 | } |
47 | 77 | } |
48 | 78 | } | ... | ... |
1 | 1 | |
2 | 2 | // # logger |
3 | 3 | |
4 | +var mergeDefaults = require('merge-defaults') | |
4 | 5 | var winston = require('winston') |
6 | +var winstonMongoDB = require('winston-mongodb') | |
5 | 7 | |
6 | 8 | exports = module.exports = function(settings) { |
7 | 9 | |
8 | - var logger = module.exports = new (winston.Logger)({ | |
9 | - transports: [ | |
10 | - new (winston.transports.Console)({ | |
11 | - colorize: true | |
12 | - }) | |
13 | - ] | |
10 | + var transports = [] | |
11 | + | |
12 | + if (settings.logger['console']) | |
13 | + transports.push( | |
14 | + new winston.transports.Console( | |
15 | + settings.output | |
16 | + ) | |
17 | + ) | |
18 | + | |
19 | + if (settings.logger.mongo) | |
20 | + transports.push( | |
21 | + new winstonMongoDB.MongoDB( | |
22 | + mergeDefaults( | |
23 | + settings.output, | |
24 | + settings.mongo | |
25 | + ) | |
26 | + ) | |
27 | + ) | |
28 | + | |
29 | + if (settings.logger.file) | |
30 | + transports.push( | |
31 | + new winston.transports.File( | |
32 | + mergeDefaults( | |
33 | + settings.output, | |
34 | + settings.logger.file | |
35 | + ) | |
36 | + ) | |
37 | + ) | |
38 | + | |
39 | + var logger = new winston.Logger({ | |
40 | + transports: transports | |
14 | 41 | }) |
15 | 42 | |
16 | 43 | return logger | ... | ... |
请
注册
或
登录
后发表评论