diff options
author | Marvin Borner | 2018-10-25 19:00:34 +0200 |
---|---|---|
committer | Marvin Borner | 2018-10-25 19:00:34 +0200 |
commit | 185e0f26c6680c64cb5f2befdedd0cc3bbf09df5 (patch) | |
tree | 40e293a98eabb951863cfce7807e1268616963da /src/hooks |
Added file structure for featherjs
Diffstat (limited to 'src/hooks')
-rw-r--r-- | src/hooks/log.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/hooks/log.js b/src/hooks/log.js new file mode 100644 index 0000000..37e9403 --- /dev/null +++ b/src/hooks/log.js @@ -0,0 +1,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); + } + }; +}; |