Search code examples
playframeworkplayframework-2.0logback

Play Framework - Change the log file location


I use a external logback file uing "Dlogger.file" as follow,

.....    -Dconfig.file="C:\temp\application.conf" **-Dlogger.file="c:\temp\logback.xml"** -Dpidfile.path=NULL -Dhttps.port=443 -Dhttp.por ..............

and my logback.xml file looks lile this,

<configuration>    
  <conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
 <file>${application.home}/application.log</file>
 <encoder>enter code here
   <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
 </encoder>
</appender>

Instead of ${application.home} (in the logback.xml file) I want to replace it with a key defined in the application.conf like

application.logpath="c:/temp"

or in other words I want to define the log file location(path) in the application.conf.


Solution

  • Add underneath <configuration>:

    <property resource="application.conf" />
    

    then use ${application.logpath}:

    <file>${application.logpath}/application.log</file>