var log4js = require('log4js');log4js.configure({ appenders: [ { type: 'console' }, { type: 'file', filename: 'd:/logs/my-app.log', category: 'my-app' } ]});var log = log4js.getLogger('my-app');log.setLevel('INFO');
/// catch 404 and forwarding to error handlerapp.use(function(req, res, next) { log.error("==========404==============="); var err = new Error('Not Found'); err.status = 404; next(err);});/// error handlers// development error handler// will print stacktraceif (app.get('env') === 'development') { app.use(function(err, req, res, next) { log.error("开发环境==========="+err); res.status(err.status || 500); res.render('error', { message: err.message, error: err }); });}// production error handler// no stacktraces leaked to userapp.use(function(err, req, res, next) { log.error("生产环境==========="+err); res.status(err.status || 500); res.render('error', { message: err.message, error: {} });});/*process.on('uncaughtException', function(err) { log.error("uncaughtException==========="+err);});*/
新闻热点
疑难解答