我正在研究Wildfly 9/10。 我使用自定义Log4j2配置文件编写了我的Web应用程序。
<configuration status="INFO">
<Appenders>
<RollingFile name="General" fileName="D:/logs/general/general.log"
filePattern="D:/logs/general/$${date:yyyy-MM}/general-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout
pattern="%d{ABSOLUTE} %level{length=5} [%thread] %logger{1} - %msg%n" />
<SizeBasedTriggeringPolicy size="20 MB" />
</RollingFile>
<Async name="asyncGeneral" bufferSize="10" includeLocation="true">
<AppenderRef ref="General" />
</Async>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="asyncGeneral" />
</Root>
</Loggers>
配置文件正确包含在war jar lib中。
结果是,当我运行Web应用程序时,它会生成文件:
D:/logs/general.log
但是它继续在服务器控制台上打印日志,而文件保持为空。
相同的配置在独立应用程序上正常运行。 我错过了什么?
UPDATE 当我部署我的应用程序时,服务器打印此调试级别信息:
12:58:17,190 INFO [stdout] (ServerService Thread Pool -- 64) 2016-06-16 12:58:17,190 ServerService Thread Pool -- 64 DEBUG createAppender(={General}, errorRef="null", blocking="true", shutdownTimeout="0", bufferSize="10", name="asyncGeneral", includeLocation="true", Filter=null, Configuration(vfs:/C:/Windows/System32/content/sec-api.war/WEB-INF/lib/com.application.jar/log4j2.xml), ignoreExceptions="true")
12:58:17,194 INFO [stdout] (ServerService Thread Pool -- 64) 2016-06-16 12:58:17,194 ServerService Thread Pool -- 64 DEBUG createAppenders(={Console, RoutingAppender, General,asyncGeneral})
12:58:17,196 INFO [stdout] (ServerService Thread Pool -- 64) 2016-06-16 12:58:17,196 ServerService Thread Pool -- 64 DEBUG reateAppenderRef(ref="asyncGeneral", level="null", Filter=null)
12:58:17,200 INFO [stdout] (ServerService Thread Pool -- 64) 2016-06-16 12:58:17,200 ServerService Thread Pool -- 64 DEBUG createLogger(additivity="null", level="DEBUG", includeLocation="null", ={async, asyncGeneral, asyncDebug}, ={}, Configuration(vfs:/C:/Windows/System32/content/sec-api.war/WEB-INF/lib/com.klopotek.core-1.3.0-SNAPSHOT.jar/log4j2.xml), Filter=null)
12:58:17,225 INFO [stdout] (ServerService Thread Pool -- 64) 2016-06-16 12:58:17,224 ServerService Thread Pool -- 64 DEBUG Registering MBean org.apache.logging.log4j2:type=/sec-api,component=AsyncAppenders,name=asyncGeneral
答案 0 :(得分:0)
您的配置仅显示RollingFile和Async Appender。然而,日志清楚地显示了Console和Routing appender。我看到对两个不同配置文件的引用,所以看起来你可能正在使用CompositeConfiguration?在任何情况下,您显示的配置都与日志消息不一致,因此很难说出问题所在。