diff --git a/lib/application.js b/lib/application.js index 47be2a20c1a..310e6dfef21 100644 --- a/lib/application.js +++ b/lib/application.js @@ -614,7 +614,7 @@ app.listen = function listen() { function logerror(err) { /* istanbul ignore next */ - if (this.get('env') !== 'test') console.error(err.stack || err.toString()); + if (this.get('env') !== 'test') console.error(err); } /** diff --git a/test/app.js b/test/app.js index c1e815a052d..05f4fa3d91e 100644 --- a/test/app.js +++ b/test/app.js @@ -118,3 +118,36 @@ describe('without NODE_ENV', function(){ assert.strictEqual(app.get('env'), 'development') }) }) + +describe('default error logging', function () { + before(function () { + this.error = console.error + this.env = process.env.NODE_ENV + process.env.NODE_ENV = 'development' + }) + + after(function () { + console.error = this.error + process.env.NODE_ENV = this.env + }) + + it('should log the error object', function (done) { + var app = express() + var error = new Error('boom', { cause: new Error('cause') }) + + console.error = function (value) { + assert.strictEqual(value, error) + done() + } + + app.use(function (req, res, next) { + next(error) + }) + + request(app) + .get('/') + .expect(500, function (err) { + if (err) done(err) + }) + }) +})