Created
April 3, 2018 15:39
-
-
Save bre7/3e625c51ed9c9344e449c03ec2a1b8ca to your computer and use it in GitHub Desktop.
Vapor 3 Logging Middleware example
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 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