Registration of the configuration in the Play Framework at startup at startup

I set up logging in the Play Framework application. When I launch the application in prod or dev mode or run the comand (play test) command, everything works fine, but the test cannot be executed when I run their β€œautomatic game 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 that execute the successfully executed 'play auto-test' command. Tell us how to set up logging in Play (output to a file) that runs and runs tests in "play auto-test"!

+6
source share
2 answers

Thi is pretty much a game! error. This is not caused by the fact that you configured log4j with a separate file, although it will hide another error message: "play.tmp is null when it should be play.tmp = none" (something about this - get this if you delete the custon log4j.xml file and repeat "play auto-test"). The problem is that even if you set play.tmp = none, it still won't work. Also, if you compare your online documentation with Play! console output, you will already understand that something is wrong:

The docs say:

"The auto-test command does the same thing as the test command, but it automatically launches the browser, starts all tests, and stops."

Sais console (when you do an "automatic test"):

 ATTENTION: You're running Play! in DEV mode ~ ~ Go to http://localhost:9000/@tests to run the tests ~ 
+1
source

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 
+1
source

Source: https://habr.com/ru/post/902946/


All Articles