Last active
January 23, 2018 17:23
-
-
Save wsargent/36e6c3a56b6aedc8db77687ee5ab8c69 to your computer and use it in GitHub Desktop.
Supports tracer bullet dynamic logging
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
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