Comparing version 1.4.0 to 1.5.0
@@ -17,3 +17,4 @@ 'use strict'; | ||
root: false, | ||
exclude: [] | ||
exclude: [], | ||
uncaughtException: false | ||
} | ||
@@ -30,3 +31,3 @@ }; | ||
// Setup log queue and flush intervals | ||
// Setup log queue | ||
@@ -50,4 +51,30 @@ const uri = `https://logs-01.loggly.com/bulk/${settings.token}`; | ||
// Setup flush intervals | ||
const timerId = setInterval(flush, settings.intervalMsec); | ||
// Listen to system exceptions | ||
if (settings.uncaughtException) { | ||
process.once('uncaughtException', (err) => { | ||
const uncaught = internals.update('error'); | ||
uncaught.error = { | ||
message: err.message, | ||
stack: err.stack, | ||
data: err.data | ||
}; | ||
uncaught.tags = ['bananas', 'uncaught', 'error']; | ||
updates.push(uncaught); | ||
return flush((ignore) => { | ||
process.exit(1); | ||
}); | ||
}); | ||
} | ||
// Listen to server events | ||
const onPostStop = function (srv, nextExt) { | ||
@@ -54,0 +81,0 @@ |
{ | ||
"name": "bananas", | ||
"description": "Minimal Loggly hapi plugin", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/hueniverse/bananas", |
@@ -252,2 +252,39 @@ 'use strict'; | ||
}); | ||
it('logs uncaughtException event', { parallel: false }, (done) => { | ||
const server = new Hapi.Server({ debug: false }); | ||
server.connection(); | ||
const settings = { | ||
token: 'abcdefg', | ||
intervalMsec: 50, | ||
uncaughtException: true | ||
}; | ||
let updates = []; | ||
const orig = Wreck.post; | ||
Wreck.post = function (uri, options, next) { | ||
updates = updates.concat(options.payload.split('\n')); | ||
return next(); | ||
}; | ||
const exit = process.exit; | ||
process.exit = (code) => { | ||
process.exit = exit; | ||
Wreck.post = orig; | ||
expect(updates.length).to.equal(2); | ||
expect(code).to.equal(1); | ||
done(); | ||
}; | ||
server.register({ register: Bananas, options: settings }, (err) => { | ||
expect(err).to.not.exist(); | ||
process.emit('uncaughtException', new Error('boom')); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13466
314