Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Supports tracer bullet dynamic logging
package controllers
import javax.inject._
import play.api.mvc._
@Singleton
class TracerBulletController @Inject() extends Controller {
private val logger = org.slf4j.LoggerFactory.getLogger("application")
/*
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
<Name>TRACER_FILTER</Name>
<Marker>TRACER</Marker>
<OnMatch>ACCEPT</OnMatch>
</turboFilter>
*/
private val tracerMarker = org.slf4j.MarkerFactory.getMarker("TRACER")
def generateMarker(implicit request: RequestHeader): org.slf4j.Marker = {
// You can return null here, but I prefer to at least have a base do-nothing marker...
val marker = org.slf4j.MarkerFactory.getDetachedMarker("dynamic")
request match {
case r if r.getQueryString("trace").nonEmpty =>
marker.add(tracerMarker)
marker
case other =>
marker
}
}
def index = Action { implicit request =>
val marker = generateMarker
if (logger.isTraceEnabled(marker)) {
logger.trace(marker, "Hello world!")
}
Ok("hello world")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.