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

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

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