Camel 未使用log4j2记录应用程序日志

vlju58qv  于 2022-11-07  发布在  Apache
关注(0)|答案(2)|浏览(168)

我在我的应用程序中使用Sping Boot 和Apache Camel,并在JBoss EAP 7.3.0中部署为war文件。log4j.properties:

log4j.rootLogger = INFO, out, FILE

log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n

log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=fileName.log
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.MaxFileSize=200MB
log4j.appender.FILE.MaxBackupIndex=20
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n

现在,我已经转到log4j 2.17.1,并使用下面的lg4j2.properties:

rootLogger.level = INFO
property.filename = fileName.log
appenders = FILE, console

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d %5p [%t] (%F:%L) - %m%n

appender.FILE.type = RollingFile
appender.FILE.name = File
appender.FILE.fileName = ${filename}
appender.FILE.filePattern = ${filename}.%d{yyyy-MM-dd}
appender.FILE.layout.type = PatternLayout
appender.FILE.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
appender.FILE.policies.type = Policies
appender.FILE.policies.time.type = TimeBasedTriggeringPolicy
appender.FILE.policies.time.interval = 1

rootLogger.appenderRefs = FILE, console

rootLogger.appenderRef.console.ref = STDOUT
rootLogger.appenderRef.FILE.ref = File

但现在,在应用程序启动过程中,只有以下日志进入,并且没有日志从应用程序中获取:
2022-08-13 00:52:12上下文加载器[信息]根Web应用程序上下文:初始化开始时间2022-08-13 00:52:31上下文加载器[信息]根Web应用程序上下文在19250毫秒内初始化
有谁能告诉我我做错了什么吗?
要补充的是,我可以在启动过程中看到Sping Boot ApplicationContext的日志,但不能看到应用程序记录的日志。这有点奇怪。

ht4b089n

ht4b089n1#

我也不知道您是如何配置和打包的,但是您可能需要通过jboss-deployment-structure.xml(位于war/WEB-INF或ear/META-INF中)排除日志记录子系统:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
  <deployment>
    <exclude-subsystems>
      <!-- disable the logging subsystem because the application manages its own logging independently -->
      <subsystem name="logging" />
    </exclude-subsystems>
  </deployment>
</jboss-deployment-structure>

对于ear,您还需要通过sub-deployment元素处理任何包含的模块的排除,或者尝试使用ear-exclusions-cascaded-to-sub-deployment(从jboss-deployment-structure:1.3开始可用):

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
  <ear-exclusions-cascaded-to-subdeployments>true</ear-exclusions-cascaded-to-subdeployments>
  <deployment>
    <exclude-subsystems>
      <!-- disable the logging subsystem because the application manages its own logging independently -->
      <subsystem name="logging" />
    </exclude-subsystems>
  </deployment>
</jboss-deployment-structure>
0g0grzrc

0g0grzrc2#

请确保使用了所有依赖项。
日志管理系统的日志管理系统
要登录到一个文件,你可以参考下面的链接。它显示了log4j2.properties文件。https://howtodoinjava.com/log4j2/log4j2-properties-example/
我希望这对你有帮助

相关问题