Skip to content

Instantly share code, notes, and snippets.

@ryanb93
Created December 21, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanb93/d5bd6bf59f59c809427b4038d73a07f2 to your computer and use it in GitHub Desktop.
Save ryanb93/d5bd6bf59f59c809427b4038d73a07f2 to your computer and use it in GitHub Desktop.
Finatra debug log per request
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
...
<turboFilter class="ch.qos.logback.classic.turbo.DynamicThresholdFilter">
<Key>X-Log-Level</Key>
<DefaultThreshold>INFO</DefaultThreshold>
<OnHigherOrEqual>ACCEPT</OnHigherOrEqual>
<OnLower>DENY</OnLower>
<MDCValueLevelPair>
<value>TRACE</value>
<level>TRACE</level>
</MDCValueLevelPair>
<MDCValueLevelPair>
<value>DEBUG</value>
<level>DEBUG</level>
</MDCValueLevelPair>
</turboFilter>
...
</configuration>
import com.hotels.dps.rest.filters.LogLevelFilter._
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.{Service, SimpleFilter}
import com.twitter.util.Future
import org.slf4j.MDC
object LogLevelFilter {
val LogLevelKey: String = "X-Log-Level"
}
class LogLevelFilter extends SimpleFilter[Request, Response] {
override def apply(request: Request, service: Service[Request, Response]): Future[Response] = {
request.headerMap.get(LogLevelKey).foreach(logLevel => MDC.put(LogLevelKey, logLevel))
service(request).ensure {
MDC.remove(LogLevelKey)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment