正在显示
2 个修改的文件
包含
17 行增加
和
9 行删除
1 | 1 | ||
2 | // # boot - error handler | 2 | // # boot - error handler |
3 | 3 | ||
4 | +var mergeDefaults = require('merge-defaults') | ||
4 | var _ = require('underscore') | 5 | var _ = require('underscore') |
5 | var util = require('util') | 6 | var util = require('util') |
6 | 7 | ||
@@ -67,13 +68,6 @@ exports = module.exports = function(logger, settings) { | @@ -67,13 +68,6 @@ exports = module.exports = function(logger, settings) { | ||
67 | 68 | ||
68 | // set error level | 69 | // set error level |
69 | var level = (res.statusCode < 500) ? 'warn' : 'error' | 70 | var level = (res.statusCode < 500) ? 'warn' : 'error' |
70 | - logger[level](error) | ||
71 | - | ||
72 | - // set error back to warning if it was warn | ||
73 | - // logger level type = "warn" | ||
74 | - // req.flash messages type = "warning" | ||
75 | - if (level === 'warn') | ||
76 | - level = 'warning' | ||
77 | 71 | ||
78 | // if we have a mongoose validation err | 72 | // if we have a mongoose validation err |
79 | // then we know to output all the errors | 73 | // then we know to output all the errors |
@@ -92,7 +86,10 @@ exports = module.exports = function(logger, settings) { | @@ -92,7 +86,10 @@ exports = module.exports = function(logger, settings) { | ||
92 | res.send(error.message) | 86 | res.send(error.message) |
93 | }, | 87 | }, |
94 | html: function() { | 88 | html: function() { |
95 | - req.flash(level, error.message) | 89 | + // set error back to warning if it was warn |
90 | + // logger level type = "warn" | ||
91 | + // req.flash messages type = "warning" | ||
92 | + req.flash(level === 'warn' ? 'warning' : level, error.message) | ||
96 | res.redirect('back') | 93 | res.redirect('back') |
97 | }, | 94 | }, |
98 | json: function() { | 95 | json: function() { |
@@ -100,6 +97,17 @@ exports = module.exports = function(logger, settings) { | @@ -100,6 +97,17 @@ exports = module.exports = function(logger, settings) { | ||
100 | } | 97 | } |
101 | }) | 98 | }) |
102 | 99 | ||
100 | + if (_.isObject(req.log)) { | ||
101 | + req.log.response_time = new Date().getTime() - req.log.response_time | ||
102 | + req.log.status = res.statusCode | ||
103 | + req.log.response_type = res.get('Content-Type') | ||
104 | + req.log.response_body = error | ||
105 | + } else { | ||
106 | + req.log = error | ||
107 | + } | ||
108 | + | ||
109 | + logger[level](req.log) | ||
110 | + | ||
103 | }) | 111 | }) |
104 | 112 | ||
105 | } | 113 | } |
1 | { | 1 | { |
2 | "name": "igloo", | 2 | "name": "igloo", |
3 | - "version": "0.0.4-rc.5", | 3 | + "version": "0.0.4-rc.6", |
4 | "description": "Igloo is a lightweight, fast, and minimal framework for rapid development", | 4 | "description": "Igloo is a lightweight, fast, and minimal framework for rapid development", |
5 | "main": "./lib", | 5 | "main": "./lib", |
6 | "repository": { | 6 | "repository": { |
请
注册
或
登录
后发表评论