Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(logging): use service query parameter in activityEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
philbooth committed Sep 21, 2015
1 parent ab4d815 commit 243879a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ Lug.prototype.activityEvent = function(event, request, data) {
if (request.headers['user-agent']) {
info.userAgent = request.headers['user-agent']
}
if (request.payload && request.payload.service) {
info.service = request.payload.service
try {
// request.payload and request.query are not always set in the unit tests
info.service = request.payload.service || request.query.service
} catch (err) {
}
Object.keys(data).forEach(function (key) {
info[key] = data[key]
Expand Down
33 changes: 33 additions & 0 deletions test/local/log_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,39 @@ test(
}
)

test(
'log.activityEvent with service query parameter',
function (t) {
log.activityEvent('foo', {
headers: {},
payload: {},
query: {
service: 'wibble'
}
}, {
uid: 'bar'
})

t.equal(logger.info.callCount, 1, 'logger.info was called once')
var args = logger.info.args[0]
t.equal(Object.keys(args[1]).length, 3, 'second argument had three properties')
t.equal(args[1].service, 'wibble', 'service property was correct')

t.equal(statsd.write.callCount, 1, 'statsd.write was called once')
t.equal(statsd.write.args[0][0], args[1], 'statsd.write argument was correct')

t.equal(logger.debug.callCount, 0, 'logger.debug was not called')
t.equal(logger.error.callCount, 0, 'logger.error was not called')
t.equal(logger.critical.callCount, 0, 'logger.critical was not called')
t.equal(logger.warn.callCount, 0, 'logger.warn was not called')

t.end()

logger.info.reset()
statsd.write.reset()
}
)

test(
'log.activityEvent with extra data',
function (t) {
Expand Down

0 comments on commit 243879a

Please sign in to comment.