Skip to content

Instantly share code, notes, and snippets.

@bre7
Created April 3, 2018 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bre7/3e625c51ed9c9344e449c03ec2a1b8ca to your computer and use it in GitHub Desktop.
Save bre7/3e625c51ed9c9344e449c03ec2a1b8ca to your computer and use it in GitHub Desktop.
Vapor 3 Logging Middleware example
import Foundation
import Vapor
/// Logs all requests that pass through it.
final class LogMiddleware: Middleware, Service {
let log: Logger
/// Creates a new `LogMiddleware`.
init(log: Logger) { self.log = log }
/// See `Middleware.respond(to:)`
func respond(to request: Request, chainingTo next: Responder) throws -> Future<Response> {
log.verbose("[\(Date())] \(request.http.method) \(request.http.url.path)")
return try next.respond(to: request)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment