Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active June 23, 2017 09:38
Show Gist options
  • Save frgomes/13599efd7e6f2dc5a7b0528615cbdd14 to your computer and use it in GitHub Desktop.
Save frgomes/13599efd7e6f2dc5a7b0528615cbdd14 to your computer and use it in GitHub Desktop.
Finatra : wrap service by a LoggingFilter
// build.sbt here: https://gist.github.com/frgomes/fb4ca804c21dd14e3224e4fc23d377e6
//TODO: should take configurations from configuration Logger in the environment.
def logWrapper(service: Service[Request, Response]): Service[Request, Response] = {
import com.twitter.logging._
import com.twitter.finagle.http.filter.{CommonLogFormatter, LoggingFilter}
val factory = LoggerFactory(
node = "",
level = Some(Level.TRACE),
handlers = List(
FileHandler(
filename = "log/oauth2.log",
rollPolicy = Policy.SigHup
)
)
)
val logger = factory()
val stringHandler = new StringHandler(BareFormatter, Some(Logger.DEBUG))
logger.addHandler(stringHandler)
logger.setUseParentHandlers(false)
val formatter = new CommonLogFormatter
val wrapper: Service[Request, Response] = (new LoggingFilter(logger, formatter)) andThen service
wrapper
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment