Browse Source

feat(log): Add structured logs for coarse_reverse

pull/1220/head
Julian Simioni 6 years ago
parent
commit
0056c0749a
No known key found for this signature in database
GPG Key ID: B9EEB0C6EE0910A1
  1. 14
      controller/coarse_reverse.js
  2. 6
      test/unit/controller/coarse_reverse.js

14
controller/coarse_reverse.js

@ -134,16 +134,20 @@ function setup(service, should_execute) {
lon: req.clean['point.lon']
};
service(req, (err, results) => {
service(req, (err, results, metadata) => {
// if there's an error, log it and bail
if (err) {
logger.info(`[controller:coarse_reverse][error]`);
logger.error(err);
logger.error('error contacting PIP service', err);
return next();
}
// log how many results there were
logger.info(`[controller:coarse_reverse][queryType:pip][result_count:${_.size(results)}]`);
const logInfo = {
controller: 'coarse_reverse',
queryType: 'pip',
response_time: _.get(metadata, 'response_time'),
result_count: _.size(results)
};
logger.info('pip', logInfo);
// now keep everything from the response that is equal to or less granular
// than the most granular layer requested. that is, if effective_layers=['county'],

6
test/unit/controller/coarse_reverse.js

@ -71,7 +71,7 @@ module.exports.tests.error_conditions = (test, common) => {
// passing res=undefined verifies that it wasn't interacted with
controller(req, undefined, next);
t.ok(logger.isErrorMessage('this is an error'));
t.ok(logger.hasErrorMessages('this is an error'));
t.end();
});
@ -903,7 +903,7 @@ module.exports.tests.failure_conditions = (test, common) => {
});
test('service returns 0 length name', (t) => {
t.plan(6);
t.plan(4);
const service = (req, callback) => {
t.deepEquals(req, { clean: { layers: ['neighbourhood'] } } );
@ -946,9 +946,7 @@ module.exports.tests.failure_conditions = (test, common) => {
t.deepEquals(res, expected);
// logger messages
t.true(logger.hasMessages('info'), '[controller:coarse_reverse][error]');
t.true(logger.hasMessages('error'), 'invalid document type, expecting: truthy, got: ');
t.true(logger.hasMessages('info'), '{ neighbourhood: [ { id: 20, name: \'\' } ] }');
t.end();

Loading…
Cancel
Save