Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why play framework 2.0 deletes log after restart?

I built package using play dist and deployed it to a webserver. Now it truncates application.log after every restart. What are the possible reasons for such behavior?

like image 667
Poma Avatar asked Nov 04 '22 12:11

Poma


1 Answers

It is done that way in the source code (delete log file on each restart), you can take a look at the source code here.

To prevent that, you can provide an alternate conf/logger.xml file and use a custom config.

For example, to create a log file in the user home folder (adapted from this documentation):

<configuration>

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

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
     <file>${user.home}/logs/myapp.log</file>
     <encoder>
       <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</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" />

  <root level="ERROR">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
  </root>

</configuration>
like image 185
ndeverge Avatar answered Nov 10 '22 19:11

ndeverge