Created
March 5, 2018 03:57
-
-
Save pedantix/2c0f65d93aeb32e1718db694ae1e6ec4 to your computer and use it in GitHub Desktop.
Vapor 3 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
public func configure( | |
_ config: inout Config, | |
_ env: inout Environment, | |
_ services: inout Services | |
) throws { | |
// App Configuration | |
configureMiddleware(&services, env: env) | |
} | |
private func configureMiddleware(_ services: inout Services, env: Environment) { | |
guard !env.isRelease else { return } | |
// configure middleware | |
var mwc = MiddlewareConfig.default() | |
mwc.use(RouteLoggingMiddleware()) | |
services.register(mwc) | |
} |
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
final class RouteLoggingMiddleware: Middleware, Service { | |
func respond(to request: Request, chainingTo next: Responder) throws -> Future<Response> { | |
let logger = try request.make(Logger.self) | |
let method = request.http.method | |
let path = request.http.uri.path | |
let query = request.http.uri.query | |
let reqString = "[\(method)]@\(path) with query:\(query)" | |
logger.debug(reqString) | |
return try next.respond(to: request) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it doesn't work
fix:
RouteLoggingMiddleware.swift
configure.swift