Created
September 15, 2023 09:31
-
-
Save dmdboi/c46d83489b9e3bfb2fb2c95078c1472a to your computer and use it in GitHub Desktop.
Adonis Request Logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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