/**
 * Define a error log middleware.
 * @function serverside.middleware.defineErrorLogMiddleware
 * @param {object} context - Server context object.
 * @return {object} - A new logger.
 * @author Taka Okunishi
 */

var newErrorLogger = require('../logger').newErrorLogger;

module.exports = function (context) {
    var logger = newErrorLogger(context);
    return function (err, req, res, next) {
        logger.error(err.stack || err);
        next(err);
    };
};