正在显示
2 个修改的文件
包含
67 行增加
和
10 行删除
@@ -12,13 +12,27 @@ exports = module.exports = function() { | @@ -12,13 +12,27 @@ exports = module.exports = function() { | ||
12 | cookieParser: '', | 12 | cookieParser: '', |
13 | mongo: { | 13 | mongo: { |
14 | host: 'localhost', | 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 | redis: { | 21 | redis: { |
19 | host: 'localhost', | 22 | host: 'localhost', |
20 | port: 6379, | 23 | port: 6379, |
21 | maxAge: 24 * 60 * 60 * 1000 | 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 | development: { | 38 | development: { |
@@ -27,7 +41,7 @@ exports = module.exports = function() { | @@ -27,7 +41,7 @@ exports = module.exports = function() { | ||
27 | port: 3000, | 41 | port: 3000, |
28 | }, | 42 | }, |
29 | mongo: { | 43 | mongo: { |
30 | - dbname: 'igloo-development', | 44 | + db: 'igloo-development', |
31 | }, | 45 | }, |
32 | redis: { | 46 | redis: { |
33 | prefix: 'igloo-development' | 47 | prefix: 'igloo-development' |
@@ -39,10 +53,26 @@ exports = module.exports = function() { | @@ -39,10 +53,26 @@ exports = module.exports = function() { | ||
39 | port: 80, | 53 | port: 80, |
40 | }, | 54 | }, |
41 | mongo: { | 55 | mongo: { |
42 | - dbname: 'igloo-production', | 56 | + db: 'igloo-production', |
43 | }, | 57 | }, |
44 | redis: { | 58 | redis: { |
45 | prefix: 'igloo-production' | 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 | // # logger | 2 | // # logger |
3 | 3 | ||
4 | +var mergeDefaults = require('merge-defaults') | ||
4 | var winston = require('winston') | 5 | var winston = require('winston') |
6 | +var winstonMongoDB = require('winston-mongodb') | ||
5 | 7 | ||
6 | exports = module.exports = function(settings) { | 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 | return logger | 43 | return logger |
请
注册
或
登录
后发表评论