Packages

Wisp integration for palabres, an opinionated logger for Gleam

Current section

Files

Jump to
palabres_wisp src palabres_wisp.gleam
Raw

src/palabres_wisp.gleam

import gleam/http
import gleam/string
import palabres
import wisp.{type Request, type Response}
/// Provides a middleware to display every incoming request for a Wisp server.\
/// Use it in your router to log request with status code, path and method.
///
/// ```gleam
/// import palabres_wisp
/// import wisp
/// pub fn router(req: wisp.Request, ctx: context) -> wisp.Response {
/// use <- palabres_wisp.log_request(req)
/// route_request(req)
/// }
/// ```
pub fn log_request(req: Request, handler: fn() -> Response) -> Response {
let response = handler()
let method = string.uppercase(http.method_to_string(req.method))
palabres.info("")
|> palabres.int("status", response.status)
|> palabres.string("method", method)
|> palabres.string("where", req.path)
|> palabres.log
response
}