java - 使用 log4j 1.2.17 时的 Stackoverflow

标签 java maven log4j stack-overflow

我在项目中使用 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 内的代码部分是

logger.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.

最佳答案

看起来您的附加程序SREWebServiceAppender正在使用JavaOauthWithCertificate,它使用log4j进行日志记录。这样,日志记录将导致更多的日志记录,并且总是以堆栈溢出结束。

您应该更新您的日志记录配置。您可以(从最明智到不太明智):

  • 不在附加程序中记录 DEBUG 消息log4j.appender.A3=com.test.sre.logging.SREWebServiceAppender ( https://logging.apache.org/log4j/1.2/faq.html#a2.9 )
  • 停止在类com.java.oauth.client.JavaOauthWithCertificate.ReadRequiredConfigurationsToObtainToken中记录DEBUG消息(我不知道那些是什么类别)
  • 停止在 root 中记录 DEBUG 消息
  • 删除附加程序log4j.appender.A3=com.test.sre.logging.SREWebServiceAppender

关于java - 使用 log4j 1.2.17 时的 Stackoverflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59186619/

相关文章:

Maven按顺序构建

java - 使用 log4j.xml 时出现 log4j 警告消息

log4j - 如何在 ADempiere 的日志文件中跟踪日志详细信息

java - 如何插入二叉搜索树上的下一个可用节点?

java - 如何修复此绑定(bind)不匹配错误?

用于搜索和排序 JSON 对象的 Java 库

java - 如何在 Java 中使用 Ruby 和 Maven?

java - 并发合并队列和监听器

gwt - 在 Maven 中运行 GWTP 真的很痛苦

java - 关闭特定 java 线程的 outputLOG 中的日志记录语句