Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Play framework logging setup, for getting proper class names into log files.
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/application.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %message%n%xException</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="INFO" />
<logger name="controllers" level="INFO" />
<logger name="com.example.myapp" level="INFO" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
package controllers
import play.api._
import play.api.mvc._
object Application extends Controller with LoggerSupport {
def index = Action { implicit req =>
logger.info(s"Serving index to ${req.remoteAddress}")
Ok(views.html.index())
}
}
package controllers
trait LoggerSupport { self =>
implicit lazy val logger =
play.api.Logger(self.getClass.getName.replaceAll("\\$$", ""))
}
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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.