All files / src/hooks hooks.logger.js

9.09% Statements 1/11
0% Branches 0/6
0% Functions 0/1
9.09% Lines 1/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  1x                                            
// A hook that logs service method before, after and error
const logger = require('winston')
 
export function log (hook) {
  let message = `${hook.type}: ${hook.path} - Method: ${hook.method}`
 
  if (hook.type === 'error') {
    message += `: ${hook.error.message}`
  }
 
  if (hook.error) {
    logger.error(message, hook.error.stack)
  } else {
    logger.debug(message)
  }
 
  logger.silly('hook.data', hook.data)
  logger.silly('hook.params', hook.params)
 
  if (hook.result) {
    logger.silly('hook.result', hook.result)
  }
}