非根级别的记录器为何未接收到日志?

huangapple go评论73阅读模式
英文:

Why are the non-root level loggers not receiving logging?

问题

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration monitorInterval="60">
	<Appenders>
		<RollingFile name="ERROR_LOG" fileName="/var/log/weblogic/app/error.log" filePattern="/var/log/weblogic/app/error.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[wW]achtwoord.*?>).*?(</.*?[wWWachtwoord].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
		<RollingFile name="DEBUG_LOG" fileName="/var/log/weblogic/app/debug.log" filePattern="/var/log/weblogic/app/debug.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[pP]assword.*?>).*?(</.*?[pPPassword].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
		<RollingFile name="FACADE_LOG" fileName="/var/log/weblogic/app/facade.log" filePattern="/var/log/weblogic/app/facade.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[pP]assword.*?>).*?(</.*?[pPPassword].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
		<RollingFile name="AUDIT_LOG" fileName="/var/log/weblogic/audit/audit.log" filePattern="/var/log/weblogic/audit/audit.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[pP]assword.*?>).*?(</.*?[pPPasword].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
	</Appenders>
	<Loggers>
		<Logger name="nl.test.app.facade" level="debug" additivity="false">
			<AppenderRef ref="FACADE_LOG"/>
		</Logger>
		<Logger name="nl.test.app.auditadapter" level="debug" additivity="false">
			<AppenderRef ref="AUDIT_LOG"/>
		</Logger>
		<Logger name="nl.test.app.proces" level="debug" additivity="false">
			<AppenderRef ref="DEBUG_LOG"/>
		</Logger>
		<Root level="debug">
			<AppenderRef ref="ERROR_LOG" />
		</Root>
	</Loggers>
</Configuration>

The issue you're experiencing could be

英文:

I am in the process of migrating an application from Log4J 1.2.16 to Log4J 2.13.3. I am using the Log4J2 1.2 to 2.13.3 bridge for this purpose. On my own development machine everything is working perfectly. However, when I deploy the application to a test server the logging gets send to the root logger only, the other log files I have defined stay empty.

The log4j2.xml configuration files on both machines are exactly the same, only the paths in the appenders differ. My development machine runs Windows, the test server runs Linux. The application is deployed to Weblogic 12.2.1.3.

I have included the log4j2.xml file on the test server below (please excuse the messy replace statement). To be clear: all logging gets send to ERROR_LOG (as that is the one referenced in the root logger), the other three logfiles are created but stay empty on the test server, while they do receive data on my development machine.

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration monitorInterval="60">
	<Appenders>
		<RollingFile name="ERROR_LOG" fileName="/var/log/weblogic/app/error.log" filePattern="/var/log/weblogic/app/error.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[wW]achtwoord.*?>).*?(</.*?[wWWachtwoord].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
		<RollingFile name="DEBUG_LOG" fileName="/var/log/weblogic/app/debug.log" filePattern="/var/log/weblogic/app/debug.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[pP]assword.*?>).*?(</.*?[pPPassword].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
		<RollingFile name="FACADE_LOG" fileName="/var/log/weblogic/app/facade.log" filePattern="/var/log/weblogic/app/facade.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[pP]assword.*?>).*?(</.*?[pPPassword].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
		<RollingFile name="AUDIT_LOG" fileName="/var/log/weblogic/audit/audit.log" filePattern="/var/log/weblogic/audit/audit.log%d{yyyy-MM-dd}.gz">
			<PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(<[^/]*?[pP]assword.*?>).*?(</.*?[pPPasword].*?>)}{$1********$2}}{(<pw>).*?(</pw>)}{$1********$2}}{(<newPW>).*?(</newPW>)}{$1********$2}|%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>
	</Appenders>
	<Loggers>
		<Logger name="nl.test.app.facade" level="debug" additivity="false">
			<AppenderRef ref="FACADE_LOG"/>
		</Logger>
		<Logger name="nl.test.app.auditadapter" level="debug" additivity="false">
			<AppenderRef ref="AUDIT_LOG"/>
		</Logger>
		<Logger name="nl.test.app.proces" level="debug" additivity="false">
			<AppenderRef ref="DEBUG_LOG"/>
		</Logger>
		<Root level="debug">
			<AppenderRef ref="ERROR_LOG" />
		</Root>
	</Loggers>
</Configuration>

On my own machine I added the location of the log4j2.xml to the classpath. On the test server I have tried adding the location to the classpath as well as setting it through the log4j.configurationFile Java VM parameter. The result in both cases is the same: all the logfiles are created at startup but only the one mentioned in the root logger (ERROR_LOG) gets logdata send to it, the other logfiles stay empty. This tells me that at least Log4J2 is able to find and read the configuration file. I have tried switching the appender which is mentioned in the root logger. In that case logging data gets send to that file, so it does not seem to be anything filesystem related.

So the question is: why do the logfiles on my test server stay empty (except the one mentioned in the root logger) but receive data on my development machine?

答案1

得分: 0

最终,在应用程序构件中仍然存在一个杂乱的log4j 1.x JAR文件,在移除该文件后,一切正常运行。你可能会期望在Log4J的调试日志中看到一些错误或至少有一些线索,但事实并非如此。不过,再说一遍,类路径问题(我猜就是这个问题)可能会比较棘手。

英文:

In the end there was still a stray log4j 1.x JAR in the application artifact, after removing that everything worked fine. You would expect some errors or at least a clue in Log4J's debug logging but that wasn't the case. Then again, classpath problems (which I guess this is) can be tricky.

huangapple
  • 本文由 发表于 2020年10月7日 17:30:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64241161.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定