Comments (6)
withAccessLog
is to be applied to the overall handler/route and RejectionHandler
s are part of that. So any rejection should finally result in a HttpResponse
and hence show up in the access log.
from accessus.
well then it does not work this way.. :)
from accessus.
Could you please come up with a minified reproducer?
from accessus.
implicit def rejectionHandler =
RejectionHandler.newBuilder().handleAll[MethodRejection] { rejections =>
val methods = rejections map (_.supported)
lazy val names = methods map (_.name) mkString ", "
respondWithHeader(Allow(methods)) {
options {
complete(s"Supported methods : $names.")
} ~
complete(MethodNotAllowed, s"HTTP method not allowed, supported methods: $names!")
}
}
.result()
def accessLog(log: LoggingAdapter): AccessLog[Long, Future[Done]] =
Sink.foreach {
case ((req, t0), res) =>
val m = req.method.value
val p = req.uri.path.toString
val e = req.uri.query().toString()
val s = res.status.intValue()
val t = (now() - t0) / 1000000
val ip = req.headers
.collectFirst { case x: `X-Forwarded-For` => x }
.map(_.addresses)
.getOrElse("NA")
log.info(s"$m $ip $p $e $s $t")
log.info(req.headers.mkString(";"))
}
private def now() = System.nanoTime()
Http().bindAndHandle(routes.rootRoutes.withAccessLog(accessLog(Logging(actorSystem, "ACCESS_LOG"))), host, port)
from accessus.
Ah, now I understand. Thanks. You are right.
From the Akka docs:
Once you have defined your custom RejectionHandler you have two options for “activating” it:
- Bring it into implicit scope at the top-level
- Supply it as an argument to the handleRejections directive
Please use 2. for the time being, because the implicit magic doesn't respect the implicitly defined rejection handler.
from accessus.
Should be fixed in v2.0.0 which should land at Maven Central eventually.
from accessus.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from accessus.