Skip to content

Instantly share code, notes, and snippets.

@dmdboi
Created September 15, 2023 09:31
Show Gist options
  • Save dmdboi/c46d83489b9e3bfb2fb2c95078c1472a to your computer and use it in GitHub Desktop.
Save dmdboi/c46d83489b9e3bfb2fb2c95078c1472a to your computer and use it in GitHub Desktop.
Adonis Request Logger
/** start/kernel.ts **/
import Server from '@ioc:Adonis/Core/Server'
Server.middleware.register([
() => import('@ioc:Adonis/Core/BodyParser'),
() => import('App/Middleware/Logger'),
])
Server.middleware.registerNamed({})
import type { HttpContextContract } from "@ioc:Adonis/Core/HttpContext";
import { default as Log } from "@ioc:Adonis/Core/Logger";
export default class Logger {
public async handle(ctx: HttpContextContract, next: () => Promise<void>) {
Log.info(`[ ${ctx.request.method()} ] ${ctx.request.url()}`);
await next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment