
// A hook that logs service method before, after and error
// See https://github.com/winstonjs/winston for documentation
// about the logger.
<%- tplTsOnly(`import { Hook } from '@feathersjs/feathers'${sc}${EOL}`) -%>
<%- tplImports('logger', '../logger') %>
<%- tplImports('util', null, 'req') %>

// To see more detailed messages, uncomment the following line:
// logger.level = 'debug'<%- sc %>

<%- tplExport('function () {', 'function (): Hook {') %>
  return <%- tplJsOrTs('context', '(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}()`)<%- sc %>

    if (typeof <%- tplJsOrTs('context', '(context as any)') -%>.toJSON === 'function' && logger.level === 'debug') {
      logger.debug('Hook Context', util.inspect(context, { colors: false }))<%- sc %>
    }

    if (context.error) {
      logger.error(context.error.stack)<%- sc %>
    }
  }<%- sc %>
}<%- tplJsOnly(sc) %>
