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

Commit 243879a

Browse files
committed
fix(logging): use service query parameter in activityEvent
1 parent ab4d815 commit 243879a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/log.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ Lug.prototype.activityEvent = function(event, request, data) {
7676
if (request.headers['user-agent']) {
7777
info.userAgent = request.headers['user-agent']
7878
}
79-
if (request.payload && request.payload.service) {
80-
info.service = request.payload.service
79+
try {
80+
// request.payload and request.query are not always set in the unit tests
81+
info.service = request.payload.service || request.query.service
82+
} catch (err) {
8183
}
8284
Object.keys(data).forEach(function (key) {
8385
info[key] = data[key]

test/local/log_tests.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,39 @@ test(
169169
}
170170
)
171171

172+
test(
173+
'log.activityEvent with service query parameter',
174+
function (t) {
175+
log.activityEvent('foo', {
176+
headers: {},
177+
payload: {},
178+
query: {
179+
service: 'wibble'
180+
}
181+
}, {
182+
uid: 'bar'
183+
})
184+
185+
t.equal(logger.info.callCount, 1, 'logger.info was called once')
186+
var args = logger.info.args[0]
187+
t.equal(Object.keys(args[1]).length, 3, 'second argument had three properties')
188+
t.equal(args[1].service, 'wibble', 'service property was correct')
189+
190+
t.equal(statsd.write.callCount, 1, 'statsd.write was called once')
191+
t.equal(statsd.write.args[0][0], args[1], 'statsd.write argument was correct')
192+
193+
t.equal(logger.debug.callCount, 0, 'logger.debug was not called')
194+
t.equal(logger.error.callCount, 0, 'logger.error was not called')
195+
t.equal(logger.critical.callCount, 0, 'logger.critical was not called')
196+
t.equal(logger.warn.callCount, 0, 'logger.warn was not called')
197+
198+
t.end()
199+
200+
logger.info.reset()
201+
statsd.write.reset()
202+
}
203+
)
204+
172205
test(
173206
'log.activityEvent with extra data',
174207
function (t) {

0 commit comments

Comments
 (0)