From 89befafbea31b7f48ddab0f5bbea0d2c70b1a2f0 Mon Sep 17 00:00:00 2001 From: John Szwaronek Date: Thu, 23 Nov 2017 08:24:20 -0500 Subject: [PATCH] Added features to debug(). context.params keys & display selected values. --- lib/services/debug.js | 10 +++++++++- tests/services/debug.test.js | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/services/debug.js b/lib/services/debug.js index 9a99b304..7965dacd 100755 --- a/lib/services/debug.js +++ b/lib/services/debug.js @@ -1,10 +1,18 @@ -module.exports = function (msg) { +module.exports = function (msg, ...fieldNames) { return context => { console.log(`* ${msg || ''}\ntype:${context.type}, method: ${context.method}`); if (context.data) { console.log('data:', context.data); } if (context.params && context.params.query) { console.log('query:', context.params.query); } if (context.result) { console.log('result:', context.result); } + + const params = context.params || {}; + console.log('params props:', Object.keys(params).sort()); + + fieldNames.forEach(name => { + console.log(`params.${name}:`, params[name]); + }); + if (context.error) { console.log('error', context.error); } }; }; diff --git a/tests/services/debug.test.js b/tests/services/debug.test.js index 5602bb99..f07f6c33 100755 --- a/tests/services/debug.test.js +++ b/tests/services/debug.test.js @@ -12,4 +12,15 @@ describe('services debug', () => { }; hooksCommon.debug('my message')(hook); }); + + it('display params props', () => { + const hook = { + type: 'before', + method: 'create', + data: { a: 'a' }, + params: { query: { b: 'b' }, foo: 'bar' }, + result: { c: 'c' } + }; + hooksCommon.debug('my message', 'query', 'foo')(hook); + }); });