使用log4j时堆栈溢出1.2.17

ax6ht2ek  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(227)

我在项目中使用log4j 1.2.17时遇到了"StackOverflow"错误。
以下是错误的堆栈跟踪

java.lang.StackOverflowError
        at org.apache.log4j.PatternLayout.format(PatternLayout.java:506)
        at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:310)
        at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)
        at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
        at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
        at org.apache.log4j.Category.callAppenders(Category.java:206)
        at org.apache.log4j.Category.forcedLog(Category.java:391)
        at org.apache.log4j.Category.debug(Category.java:260)
        at com.java.oauth.client.JavaOauthWithCertificate.ReadRequiredConfigurationsToObtainToken(JavaOauthWithCertificate.java:42)
        at com.java.oauth.client.JavaOauthWithCertificate.getTokenByCertificate(JavaOauthWithCertificate.java:112)
        at com.test.sre.service.ServiceWrapperImpl.logMessage(ServiceWrapperImpl.java:54)
        at com.test.sre.logging.SREWebServiceAppender.append(SREWebServiceAppender.java:59)
        at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
        at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
        at org.apache.log4j.Category.callAppenders(Category.java:206)
        at org.apache.log4j.Category.forcedLog(Category.java:391)
        at org.apache.log4j.Category.debug(Category.java:260)
        at com.java.oauth.client.JavaOauthWithCertificate.ReadRequiredConfigurationsToObtainToken(JavaOauthWithCertificate.java:42)
        at com.java.oauth.client.JavaOauthWithCertificate.getTokenByCertificate(JavaOauthWithCertificate.java:112)

第42行ReadRequiredConfigurationsToObtainToken中的代码部分是
记录器. debug(验证已开始
SRE Web服务附加器正在将日志写入数据库。这将调用扩展的AppenderSkeleton类以实现自定义附加器。当代码运行时,执行在此点卡住,并在特定时间后引发错误。
我已经尝试增加JVM的堆栈大小和堆大小,但还没有成功。
下面是在属性文件中设置的log4j配置

log4j.rootLogger=DEBUG, A1, A2, A3

# service will ignore this output, but somebody manually running might be interested
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%d] %-5p %c %x - %m%n

# also log to a file - again probably not monitored in production but might be handy for debugging
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.File=C:\\EnergyTrading\\logs\\debug.log
log4j.appender.A2.DatePattern='.'yyyy-MM-dd
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%d] %-5p %c %x - %m%n

#web service appender - directs log messages to 
log4j.appender.A3=com.test.sre.logging.SREWebServiceAppender

Any help on this error would be greatly helpful.
qco9c6ql

qco9c6ql1#

看起来您的appender SREWebServiceAppender正在使用JavaOauthWithCertificate,而JavaOauthWithCertificate正在使用log4j进行日志记录。这样日志记录将导致更多日志记录,并且总是以堆栈溢出结束。
您应该更新日志记录配置。您可以执行以下操作之一(从最明智到最不明智):

  • 不要在附加程式log4j.appender.A3=com.test.sre.logging.SREWebServiceAppender中记录调试消息()
  • 停止记录类com.java.oauth.client.JavaOauthWithCertificate.ReadRequiredConfigurationsToObtainToken中的DEBUG消息(我不知道这些是什么类别)
  • 停止在root中记录DEBUG消息
  • 移除附加器log4j.appender.A3=com.test.sre.logging.SREWebServiceAppender

相关问题