gpt4 book ai didi

java - Tomcat9 Log4j2 - 两个服务器之间的日志记录不同

转载 作者:太空宇宙 更新时间:2023-11-04 09:35:17 25 4
gpt4 key购买 nike

我正在运行两个不同的 Tomcat9 服务器(DEV、PROD),每个服务器都位于不同的 CentOS 7 服务提供商,并且使用相同的 log4j2.xml 生成的应用程序日志是不同的。在 DEV 版本中,我获得 com.example 的完整日志,但在 PROD 版本中,我仅获得 org.hibernate 日志记录。

两台服务器的配置类似(如下所示)。两者都使用相同的 log4j2.xml,部署在每个 Tomcat 上的 MyWebApp.war 是相同的。

两个 Tomcat 都是标准安装 - 这意味着我没有向其中任何一个添加任何 log4j jar 或属性。

我希望有人需要考虑一些事情。

谢谢

鲍勃

开发配置:

 Provider: VPS
rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64

java -cp /opt/tomcat/apache-tomcat-9.0.20/lib/catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/9.0.20
Server built: May 3 2019 22:26:00 UTC
Server number: 9.0.20.0
OS Name: Linux
OS Version: 2.6.32-042stab127.2
Architecture: amd64
JVM Version: 1.8.0_212-b04
JVM Vendor: Oracle Corporation

产品配置:

 Provider: Jelastic
rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64

java -cp /opt/tomcat/lib/catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/9.0.19
Server built: Apr 12 2019 14:22:48 UTC
Server number: 9.0.19.0
OS Name: Linux
OS Version: 3.10.0
Architecture: amd64
JVM Version: 1.8.0_202-b08
JVM Vendor: Oracle Corporation

log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="logPath">/home/example/logs</Property>
</Properties>

<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d [%t] %-5p [%C.%M()] %m%n" />
</Console>

<RollingFile name="rollingFile" fileName="${logPath}/MyWebApp.log"
filePattern="${logPath}/cucumber-log_%d{yyyy-MM-dd}.log">
<PatternLayout
pattern="%d [%t] %-5p [%C.%M()] %m%n" />
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
</Policies>
</RollingFile>
</Appenders>

<Loggers>
<Logger name="org.springframework" level="warn" additivity="false">
<AppenderRef ref="console" level="warn"/>
<AppenderRef ref="rollingFile" level="warn"/>
</Logger>
<Logger name="org.hibernate" level="debug" additivity="false">
<AppenderRef ref="console" level="debug"/>
<AppenderRef ref="rollingFile" level="debug"/>
</Logger>
<Logger name="com.example" level="trace" additivity="false">
<AppenderRef ref="console" level="trace"/>
<AppenderRef ref="rollingFile" level="trace"/>
</Logger>
<Root level="TRACE" additivity="false">
<AppenderRef ref="console" />
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>

mywebapp.war:

enter image description here

DEV MyWebApp.log( hibernate 结束并开始 mywebapp 日志记录):

2019-06-13 05:18:36,998 [main] DEBUG [org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator.initiateService()] No JtaPlatform was specified, checking resolver
2019-06-13 05:18:36,998 [main] TRACE [org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService()] Initializing service [role=org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver]
2019-06-13 05:18:37,002 [main] DEBUG [org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformResolverInitiator.initiateService()] No JtaPlatformResolver was specified, using default [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver]
2019-06-13 05:18:37,027 [main] DEBUG [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver.resolveJtaPlatform()] Could not resolve JtaPlatform, using default [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-06-13 05:18:37,028 [main] INFO [org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator.initiateService()] HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-06-13 05:18:37,031 [main] DEBUG [org.hibernate.query.spi.NamedQueryRepository.checkNamedQueries()] Checking 0 named HQL queries
2019-06-13 05:18:37,031 [main] DEBUG [org.hibernate.query.spi.NamedQueryRepository.checkNamedQueries()] Checking 0 named SQL queries
2019-06-13 05:18:37,032 [main] TRACE [org.hibernate.type.spi.TypeConfiguration.sessionFactoryCreated()] Handling #sessionFactoryCreated from [org.hibernate.internal.SessionFactoryImpl@35c7c5e] for TypeConfiguration
2019-06-13 05:18:37,036 [main] DEBUG [org.hibernate.internal.SessionFactoryRegistry.<init>()] Initializing SessionFactoryRegistry : org.hibernate.internal.SessionFactoryRegistry@2ebf0e46
2019-06-13 05:18:37,037 [main] DEBUG [org.hibernate.internal.SessionFactoryRegistry.addSessionFactory()] Registering SessionFactory: 7ffcae61-38d8-4cc8-9cc2-4889b35589f0 (<unnamed>)
2019-06-13 05:18:37,038 [main] DEBUG [org.hibernate.internal.SessionFactoryRegistry.addSessionFactory()] Not binding SessionFactory to JNDI, no JNDI name configured
2019-06-13 05:20:23,717 [ajp-nio-8009-exec-1] WARN [com.example.tanglemydata.controller.AccountController.getAllAdData()] ENTRY
2019-06-13 05:20:23,719 [ajp-nio-8009-exec-1] DEBUG [com.example.tanglemydata.service.AccountService.getAllAdData()] ENTRY
2019-06-13 05:20:23,794 [ajp-nio-8009-exec-1] TRACE [org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession()] Opening Hibernate Session. tenant=null, owner=null
2019-06-13 05:20:24,088 [ajp-nio-8009-exec-1] TRACE [org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService()] Initializing service [role=org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder]
2019-06-13 05:20:24,254 [ajp-nio-8009-exec-1] TRACE [org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService()] Initializing service [role=org.hibernate.stat.spi.StatisticsImplementor]
2019-06-13 05:20:24,295 [ajp-nio-8009-exec-1] DEBUG [org.hibernate.stat.internal.StatisticsInitiator.initiateServiceInternal()] Statistics initialized [enabled=false]
2019-06-13 05:20:24,303 [ajp-nio-8009-exec-1] TRACE [org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService()] Initializing service [role=org.hibernate.jmx.spi.JmxService]
2019-06-13 05:20:24,319 [ajp-nio-8009-exec-1] TRACE [org.hibernate.internal.SessionImpl.<init>()] Opened Session [3eb81c15-c50c-44a5-9825-5e31d3cb2172] at timestamp: 1560403224040

PROD MyWebApp.log(最后 9 条):

2019-06-13 04:39:40,435 [main] DEBUG [org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator.initiateService()] No JtaPlatform was specified, checking resolver
2019-06-13 04:39:40,437 [main] DEBUG [org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformResolverInitiator.initiateService()] No JtaPlatformResolver was specified, using default [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver]
2019-06-13 04:39:40,505 [main] DEBUG [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver.resolveJtaPlatform()] Could not resolve JtaPlatform, using default [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-06-13 04:39:40,506 [main] INFO [org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator.initiateService()] HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-06-13 04:39:40,509 [main] DEBUG [org.hibernate.query.spi.NamedQueryRepository.checkNamedQueries()] Checking 0 named HQL queries
2019-06-13 04:39:40,509 [main] DEBUG [org.hibernate.query.spi.NamedQueryRepository.checkNamedQueries()] Checking 0 named SQL queries
2019-06-13 04:39:40,513 [main] DEBUG [org.hibernate.internal.SessionFactoryRegistry.<init>()] Initializing SessionFactoryRegistry : org.hibernate.internal.SessionFactoryRegistry@34e10162
2019-06-13 04:39:40,514 [main] DEBUG [org.hibernate.internal.SessionFactoryRegistry.addSessionFactory()] Registering SessionFactory: bba8ac5f-afd5-4b89-ba16-77f5c980fa0e (<unnamed>)
2019-06-13 04:39:40,515 [main] DEBUG [org.hibernate.internal.SessionFactoryRegistry.addSessionFactory()] Not binding SessionFactory to JNDI, no JNDI name configured

DEV 命令行:

cat /proc/23517/cmdline
/usr/bin/java-Djava.util.logging.config.file=/opt/tomcat/apache-tomcat-9.0.20/conf/logging.properties-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-Djdk.tls.ephemeralDHKeySize=2048-Djava.protocol.handler.pkgs=org.apache.catalina.webresources-Dorg.apache.catalina.security.SecurityListener.UMASK=0027-Dignore.endorsed.dirs=-classpath/opt/tomcat/apache-tomcat-9.0.20/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-9.0.20/bin/tomcat-juli.jar-Dcatalina.base=/opt/tomcat/apache-tomcat-9.0.20-Dcatalina.home=/opt/tomcat/apache-tomcat-9.0.20-Djava.io.tmpdir=/opt/tomcat/apache-tomcat-9.0.20/temporg.apache.catalina.startup.Bootstrapstart

PROD 命令行:

cat /proc/19765/cmdline
/usr/java/jdk1.8.0_202/bin/java.orig-javaagent:/java_agent/jelastic-gc-agent.jar=period=300,debug=0-XX:+UseStringDeduplication-XX:+UseG1GC-Xmaxf0.3-Xminf0.1-Xmx614M-Xmn30M-Xms32M-Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-DReceiverIp=-DMagicPort=-XX:+UseCompressedOops-server-Djvm=tomcat-Djava.awt.headless=true-Djava.net.preferIPv4Stack=false-DjvmRid=-Djdk.tls.ephemeralDHKeySize=2048-Djava.protocol.handler.pkgs=org.apache.catalina.webresources-Dorg.apache.catalina.security.SecurityListener.UMASK=0027-Dignore.endorsed.dirs=-classpath/opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar-Dcatalina.base=/opt/tomcat-Dcatalina.home=/opt/tomcat-Djava.io.tmpdir=/opt/tomcat/temporg.apache.catalina.startup.Bootstrapstarttomcat

最佳答案

我是OP。问题解决了。

这是由于 Jelastic 在 Tomcat 部署后没有刷新 webapps 文件夹。因此,使用旧的 log4j2.xml。

鲍勃

关于java - Tomcat9 Log4j2 - 两个服务器之间的日志记录不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56588667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com