diff options
-rw-r--r-- | hooks/logging.ts | 13 | ||||
-rw-r--r-- | services/index.ts | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/hooks/logging.ts b/hooks/logging.ts new file mode 100644 index 0000000..30353ae --- /dev/null +++ b/hooks/logging.ts @@ -0,0 +1,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; +}; + diff --git a/services/index.ts b/services/index.ts index ce20901..8d77429 100644 --- a/services/index.ts +++ b/services/index.ts @@ -6,6 +6,7 @@ import Votes from './votes/votes.service'; import Auth from './auth/auth.service'; import tryAuthenticate from '../hooks/tryAuthenticate'; +import logging from '../hooks/logging'; export default (app: Application): void => { app.configure(Auth); @@ -17,6 +18,9 @@ export default (app: Application): void => { app.hooks({ before: { all: tryAuthenticate + }, + after: { + all: logging } }); }; |