- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当我使用 JUnit 测试我的应用程序时,它会按照 log4j2.xml
中的布局模式指定的方式打印日志,但是当我部署我的应用程序时在 WildFly 9 中,我不再使用相同的格式。即使是 Log4j2 中的日志级别在服务器中部署时也不会反射(reflect)。
JUnit 日志示例:
2016-02-15 11:14:16,314 DEBUG [main] b.t.r.c.XAPool - a connection's state changed to IN_POOL, notifying a thread eventually waiting for a connection
服务器日志示例:
11:11:33,796 INFO [org.quartz.core.QuartzScheduler] (ServerService Thread Pool -- 89) Scheduler quartzScheduler_$_anindya-ubuntu1455514892022 started.
Log4j2.xml:
<Configuration status="WARN" name="myapp" monitorInterval="5">
<Appenders>
<RollingFile name="RollingFile" fileName="${myapp.log-dir}/myapp.log"
filePattern="${myapp.log-dir}/$${date:yyyy-MM}/myapp-%d{MM-dd-yyyy}-%i.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="25 MB"/>
</Policies>
<DefaultRolloverStrategy max="100">
<Delete basePath="${myapp.log-dir}" maxDepth="2">
<IfFileName glob="*/myapp-*.log">
<IfLastModified age="7d">
<IfAny>
<IfAccumulatedFileSize exceeds="1 GB" />
<IfAccumulatedFileCount exceeds="1" />
</IfAny>
</IfLastModified>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.company.myapp" level="trace" additivity="false">
<AppenderRef ref="RollingFile"/>
</Logger>
<Root level="info">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
在启动服务器时,我提供以下启动属性作为 JAVA_OPTS:
export JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active='qa' -Dlog4j.configurationFile=/home/anindya/1.0/log4j2.xml -myapp.log-dir=/home/anindya/log -Dorg.jboss.logging.provider=log4j"
我在 web.xml
中没有特定设置,因为它是 Servlet 3.1 容器。但是我的 WEB-INF
中有一个 jboss-deployment-structure.xml
,如下所示:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.logging.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
最后,这是我的类路径依赖项(这里只提到相关部分):
通过所有上述设置,我仍然无法根据我的 log4j2.xml
在 WildFly 环境中配置 Log4j2。有人可以帮忙吗?
注意:我在独立模式下运行 WildFly,我想避免使用 jboss-cli
。
最佳答案
我设法通过使用下面的 jboss-deployment-structure.xml
让它工作。
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="org.apache.logging.log4j" />
</exclusions>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
我所要做的就是排除日志子系统。
关于java - 如何为部署在 WildFly 9 中的应用程序设置 Log4j2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35402632/
我是一名优秀的程序员,十分优秀!