Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

xml - Play framework logger not picking format after packaging

I have formatted the logs generated by play using logger.xml file in conf folder to get the desired format. In my local environment when i am using the normal play commands like play ~run or play -Dlogger.resource=logger.xml start. But when i do packaging with play dist and start the process with command sudo ./start -Dlogger.resource=logger.xml it is printing default logs without any format.

logger.xml

<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{HH:mm:ss.SSS} [%level] %class:%method  %msg%n </pattern>
     </encoder>
   </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%level] %class:%method  %msg%n </pattern>
    </encoder>
  </appender>

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

  <logger name="application" level="debug" additivity="false">
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="FILE"/>
  </logger>

</configuration>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You seem to be using Play 2.0.x - 2.1.x based on the fact that you are using the start script generated by play stage or play dist. According to this section in the docs and assuming your logger.xml is in your conf directory, then the suggested correct config for your file would be:

sudo ./start -Dlogger.resource=logger.xml

However, it turns out that if you name your Logback config file logger.xml then Play seems to pick the default logger.xml config file from the classpath and not yours. Which is probably why the name of the config file in the docs is called prod-logger.xml and not just logger.xml, however that is not explicitly explained.

So rename your logger.xml file to something else. For example test-logger.xml and then the following will correctly pick your Logback config:

sudo ./start -Dlogger.resource=test-logger.xml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...