简体   繁体   English

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

[英]Application logs are not getting logged using log4j2

I am using Spring Boot and Apache Camel in my application and deploying in JBoss EAP 7.3.0 as war files.我在我的应用程序中使用 Spring Boot 和 Apache Camel 并在 JBoss EAP 7.3.0 中部署为战争文件。 Previously the startup logs and logs from the application were getting logged to the log file when I was using log4j 1.x and the below log4j.properties:以前,当我使用 log4j 1.x 和以下 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

Now I have shifted to log4j 2.17.1 and using the below lg4j2.properties:现在我已经转移到 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

But now only the below logs are coming during application startup and no logs are gettig logged from the application:但是现在只有以下日志在应用程序启动期间出现,并且没有从应用程序记录日志:

2022-08-13 00:52:12 ContextLoader [INFO] Root WebApplicationContext: initialization started 2022-08-13 00:52:31 ContextLoader [INFO] Root WebApplicationContext initialized in 19250 ms 2022-08-13 00:52:12 ContextLoader [INFO] Root WebApplicationContext:初始化开始 2022-08-13 00:52:31 ContextLoader [INFO] Root WebApplicationContext 在 19250 毫秒内初始化

Can anyone please suggest what am I doing wrong?谁能建议我做错了什么?

To add, I can see the logs from Spring Boot ApplicationContext during startup, but not the logs which are logged by the application.要补充的是,我可以在启动期间看到来自 Spring Boot ApplicationContext 的日志,但看不到应用程序记录的日志。 This is kind of strange.这有点奇怪。

Please make sure you are using all the dependencies.请确保您正在使用所有依赖项。

org.apache.logging.log4j.log4j-api org.apache.logging.log4j.log4j-core org.apache.logging.log4j.log4j-api org.apache.logging.Z2E0241441F0D1BACE699

And for a logging into a file u can go ahead refer below link.对于登录文件,您可以提前 go 参考下面的链接。 It shows log4j2.properties file.它显示 log4j2.properties 文件。 https://howtodoinjava.com/log4j2/log4j2-properties-example/ https://howtodoinjava.com/log4j2/log4j2-properties-example/

I hope this helps我希望这有帮助

Also I don't know how exactly you have it configured and packaged, but you may need to exclude the logging subsystem via jboss-deployment-structure.xml (located in war/WEB-INF or ear/META-INF):另外我不知道你是如何配置和打包的,但你可能需要通过 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>

In the case of ear you'll also need to handle exclusions for any included modules via the sub-deployment elements, or try to use ear-exclusions-cascaded-to-subdeployments (available since jboss-deployment-structure:1.3):在 ear 的情况下,您还需要通过子部署元素处理任何包含模块的排除,或尝试使用 ear-exclusions-cascaded-to-subdeployments(自 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM