blob: 37e9403b4684d9ecea42830a25c383839087dafc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// A hook that logs service method before, after and error
// See https://github.com/winstonjs/winston for documentation
// about the logger.
const logger = require('../logger');
const util = require('util');
// To see more detailed messages, uncomment the following line:
// logger.level = 'debug';
module.exports = function () {
return context => {
// This debugs the service call and a stringified version of the hook context
// You can customize the message (and logger) to your needs
logger.debug(`${context.type} app.service('${context.path}').${context.method}()`);
if(typeof context.toJSON === 'function' && logger.level === 'debug') {
logger.debug('Hook Context', util.inspect(context, {colors: false}));
}
if(context.error && !context.result) {
logger.error(context.error.stack);
}
};
};
|