Created
September 9, 2014 08:44
-
-
Save dwaligora/fbec4148cc81d9da7dde to your computer and use it in GitHub Desktop.
logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var log4js = require('log4js'), | |
util = require('util'), | |
config = require('../../config'), | |
NvbUtil = require('../../lib/nvb-util'); | |
// configure loggers | |
log4js.configure(config.logger.log4js); | |
var infoLogger = new NvbUtil.Logger(config); | |
var errorLogger = new NvbUtil.Logger(config, log4js.getLogger('error-logger')); | |
/** | |
* @param {Error} err | |
* @param {Request} req | |
* @param {Response} res | |
* @param {Function} next | |
* @returns {*} | |
*/ | |
module.exports = function(err, req, res, next) { | |
var requestUtil = new NvbUtil.Request(req); | |
var msg = util.format('%s: %s %s', requestUtil.getIp(), req.method, req.url); | |
infoLogger.error(msg + ' : ' + err); | |
errorLogger.error(err); | |
if (requestUtil.getAbsoluteUrl().match(/api/g)) { | |
// @todo - prepare correct recognition for not body aware requests like /GET | |
errorLogger.info(req.body); | |
} | |
return next(err); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment