我有一个使用Spring Boot的Java webapp运行正常,我一直在使用SLF4J(使用log4j2)。 这一切都可以 - 并在我的本地Tomcat实例中注销到正确的文件 - 在类路径中没有冲突的Jars。
但是,当部署到生产环境中时,Tomcat / lib目录中似乎存在一个现有的log4j jar文件(它在WEB-INF / lib目录中击败了我自己的log4j2 jar)。我在启动时遇到一些错误,因为记录器/属性的数量并不匹配,因此似乎与我自己的配置无关。
我对生产Tomcat环境的控制有限,所以理想情况下我希望能够限制我的webapp 的类路径中包含哪些库而不更改其他人的配置部署在同一个Tomcat实例中。
因此,我的问题是: 是否可以仅从我的应用程序中排除提供的log4j jar,而是使用我提供的log4j2 jar?
提前致谢!
启动时的错误
2016-03-07 15:34:29,346 localhost-startStop-10 ERROR Error processing element appender ([configuration: null]): CLASS_NOT_FOUND
2016-03-07 15:34:29,347 localhost-startStop-10 ERROR Error processing element appender ([configuration: null]): CLASS_NOT_FOUND
2016-03-07 15:34:29,347 localhost-startStop-10 ERROR Error processing element appender ([configuration: null]): CLASS_NOT_FOUND
2016-03-07 15:34:29,348 localhost-startStop-10 ERROR Error processing element appender ([configuration: null]): CLASS_NOT_FOUND
2016-03-07 15:34:29,349 localhost-startStop-10 ERROR property contains an invalid element or attribute "value"
2016-03-07 15:34:29,349 localhost-startStop-10 ERROR Unknown object "property" of type org.apache.logging.log4j.core.config.Property is ignored.
2016-03-07 15:34:29,350 localhost-startStop-10 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2016-03-07 15:34:29,350 localhost-startStop-10 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2016-03-07 15:34:29,351 localhost-startStop-10 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2016-03-07 15:34:29,352 localhost-startStop-10 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2016-03-07 15:34:29,352 localhost-startStop-10 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2016-03-07 15:34:29,353 localhost-startStop-10 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2016-03-07 15:34:29,353 localhost-startStop-10 ERROR Unknown object "root" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2016-03-07 15:34:29,354 localhost-startStop-10 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
log4j2.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<Configuration name="PSPCC" monitorInterval="30">
<Properties>
<Property name="LOG_PATH">logs</Property>
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{--}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%wEx</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}" />
</Console>
<RollingFile name="File" fileName="${LOG_PATH}/pspcc.log"
filePattern="${LOG_PATH}/pspcc-${date:yyyy-MM-dd}.log" append="true">
<Policies>
<SizeBasedTriggeringPolicy size="1 MB" />
</Policies>
<DefaultRolloverStrategy max="3"/>
<PatternLayout pattern="${LOG_PATTERN}" />
</RollingFile>
</Appenders>
<Loggers>
<Logger name="org.hibernate" level="warn" />
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
<Logger name="org.springframework.security.saml" level="debug" />
<Logger name="org.springframework.security" level="info" />
<Root level="warn">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>