Skip to content

Commit

Permalink
Merge pull request #301 from feathers-plus/debug
Browse files Browse the repository at this point in the history
Added features to debug(). context.params keys & display selected values.
  • Loading branch information
eddyystop authored Nov 23, 2017
2 parents a132577 + 89befaf commit 3e6fc7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/services/debug.js
Original file line number Diff line number Diff line change
@@ -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); }
};
};
11 changes: 11 additions & 0 deletions tests/services/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 3e6fc7c

Please sign in to comment.