aboutsummaryrefslogtreecommitdiff
path: root/hooks/logging.ts
blob: 30353ae91e4c8146cd4ccb8193262ab0eb6cf7ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
import { HookContext } from '@feathersjs/feathers';

export default async (context: HookContext): Promise<HookContext> => {
  if (context.params.provider) {
    const { method, path, id, params: { user: { username }} } = context;
    const timestamp = new Date().toLocaleString('default', { timeStyle: 'medium', dateStyle: 'short' });
    const message = `${method.toUpperCase()}: /${path}/${id || ''}`;

    console.log(`[${timestamp}]  ${message} ${username || ''}`);
  }
  return context;
};