Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuration logging in Play Framework at start up auto-test

I configured the logging in my Play Framework application. When I run application in prod or dev mode or run test by comand (play test) - everything works fine, but test can not executes when I run their 'play auto-test'. Please help!

in application.conf:

application.log=INFO
application.log.path=/log4j.xml 

log4j.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="file" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="${application.path}/logs/application.log"/>
      <param name="MaxFileSize" value="1MB"/>
      <param name="MaxBackupIndex" value="100"/>
      <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p ~ %m %n"/>
      </layout>
  </appender>
 <logger name="play">
     <level value="error"/>
 </logger>
 <root>
     <priority value="error"/>
     <appender-ref ref="file"/>
 </root>
</log4j:configuration>

When I use the following log4j.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender">
      <param name="Target" value="System.out"/>
      <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%m%n"/>
      </layout>
  </appender>
 <logger name="play">
     <level value="debug"/>
 </logger>
 <root>
     <priority value="info"/>
     <appender-ref ref="console"/>
 </root>
</log4j:configuration>     

tests running the command 'play auto-test' successfully executed. Please tell how configure logging in Play (output to file) that run and executes tests in 'play auto-test'!

like image 546
Ivan Schetinin Avatar asked Dec 02 '11 16:12

Ivan Schetinin


2 Answers

The answer was very simple

in application.conf:

%test.application.log=INFO
%test.application.log.path=/log4j.xml

application.log=INFO
application.log.path=/log4j.properties
application.log.system.out=off

log4j.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender">
      <param name="Target" value="System.out"/>
      <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%m%n"/>
      </layout>
  </appender>
 <logger name="play">
     <level value="debug"/>
 </logger>
 <root>
     <priority value="info"/>
     <appender-ref ref="console"/>
 </root>
</log4j:configuration>

log4j.properties:

log4j.rootLogger=ERROR, Rolling
log4j.logger.play=INFO
log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.Rolling.File=${application.path}/logs/application.log
log4j.appender.Rolling.MaxFileSize=1MB
log4j.appender.Rolling.MaxBackupIndex=100
log4j.appender.Rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.Rolling.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m %n
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n
like image 41
Ivan Schetinin Avatar answered Oct 05 '22 03:10

Ivan Schetinin


Thi is pretty much a Play! bug. It's not caused by the fact that you've configured log4j with a separate file, though doing that will hide another error message: "play.tmp is null when it should be play.tmp=none" (something to this liking - you'll get this if you remove your custon log4j.xml file and re-do "play auto-test"). Problem is that even if you set that to play.tmp=none it will still not work. Besides, if you compare their online documentation to Play!'s console output you'll already realize that something's wrong:

The docs say:

"The 'auto-test' command do the same than the 'test' command, but it automatically launch a browser, run all the tests, and stop."

Console sais (when you do "play auto-test"):

ATTENTION: You're running Play! in DEV mode
~
~ Go to http://localhost:9000/@tests to run the tests
~
like image 200
Shivan Dragon Avatar answered Oct 05 '22 02:10

Shivan Dragon