打包后Play框架记录器未选择格式 [英] Play framework logger not picking format after packaging
问题描述
我已经格式化了使用conf
文件夹中的logger.xml
文件播放所生成的日志,以获取所需的格式.在我的本地环境中,当我使用普通播放命令(如play ~run
或play -Dlogger.resource=logger.xml
)启动时.但是,当我使用play dist
打包并使用命令sudo ./start -Dlogger.resource=logger.xml
开始该过程时,它将打印没有任何格式的默认日志.
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>
推荐答案
您似乎正在使用Play 2.0.x-2.1.x,因为您使用的是play stage
或play dist
.
根据文档中的此部分,并假设您的logger.xml
位于您的conf
目录,则建议的文件正确配置为:
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
但是,事实证明,如果您将Logback配置文件命名为logger.xml
,则Play似乎会从类路径中选择默认的logger.xml
配置文件,而不是您的.这可能就是为什么在文档中将配置文件的名称称为prod-logger.xml
而不是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.
因此,将您的logger.xml
文件重命名为其他名称.例如,test-logger.xml
,然后以下内容将正确选择您的Logback配置:
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
这篇关于打包后Play框架记录器未选择格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!