log4j:ERROR 转换日期时发生错误
我在日志中发现了这个异常:
log4j:ERROR 转换日期时发生错误。 java.lang.NullPointerException 在 java.lang.System.arraycopy(本机方法) 在 java.lang.AbstractStringBuilder.getChars(AbstractStringBuilder.java:328) 在 java.lang.StringBuffer.getChars(StringBuffer.java:201) 在org.apache.log4j.helpers.ISO8601DateFormat.format(ISO8601DateFormat.java:130) 在 java.text.DateFormat.format(DateFormat.java:316) 在 org.apache.log4j.helpers.PatternParser$DatePatternConverter.convert(PatternParser.java:443) 在 org.apache.log4j.helpers.PatternConverter.format(PatternConverter.java:65) 在 org.apache.log4j.PatternLayout.format(PatternLayout.java:506) 在 org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:310) 在 org.apache.log4j.WriterAppender.append(WriterAppender.java:162) 在 org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251) 在org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66) 在 org.apache.log4j.Category.callAppenders(Category.java:206) 在 org.apache.log4j.Category.forcedLog(Category.java:391) 在 org.apache.log4j.Category.info(Category.java:666) 在 org.obliquid.db.ConnectionManager.releaseConnection(ConnectionManager.java:313) 在 org.obliquid.db.ConnectionManager.finalize(ConnectionManager.java:331) 在 java.lang.ref.Finalizer.invokeFinalizeMethod(本机方法) 在 java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83) 在 java.lang.ref.Finalizer.access$100(Finalizer.java:14) 在 java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
我认为这可能是由我的 log4j.properties 文件引起的,特别是 ConversionPattern 引起的。关于如何修复有什么想法吗?
#Updated at Wed Sep 14 21:57:51 CEST 2011
#Wed Sep 14 21:57:51 CEST 2011
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.rootLogger=INFO, stdout
log4j.appender.R.File=yamweb.log
log4j.appender.R.MaxFileSize=1000KB
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.logger.yamweb=DEBUG
log4j.logger.org.springframework=INFO
log4j.logger.org.springframework.beans=DEBUG
log4j.logger.com.amazonaws=WARN
更新:实际上,查看PatternLayout JavaDoc,我什至没有提到日期格式。
d 用于输出日志事件的日期。日期转换说明符后面可以跟着括在大括号内的日期格式说明符。例如,%d{HH:mm:ss,SSS} 或 %d{dd MMM yyyy HH:mm:ss,SSS}。如果未给出日期格式说明符,则假定为 ISO8601 格式。
我添加了一个显式转换模式:%d{yyyy-MM-dd HH:mm:ss} [%t] %p %c - %m%n
——查看日志并如果有帮助的话我会让你知道的。
更新2:问题不再发生。
I found this exception in my logs:
log4j:ERROR Error occured while converting date.
java.lang.NullPointerException
at java.lang.System.arraycopy(Native Method)
at java.lang.AbstractStringBuilder.getChars(AbstractStringBuilder.java:328)
at java.lang.StringBuffer.getChars(StringBuffer.java:201)
at org.apache.log4j.helpers.ISO8601DateFormat.format(ISO8601DateFormat.java:130)
at java.text.DateFormat.format(DateFormat.java:316)
at org.apache.log4j.helpers.PatternParser$DatePatternConverter.convert(PatternParser.java:443)
at org.apache.log4j.helpers.PatternConverter.format(PatternConverter.java:65)
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.info(Category.java:666)
at org.obliquid.db.ConnectionManager.releaseConnection(ConnectionManager.java:313)
at org.obliquid.db.ConnectionManager.finalize(ConnectionManager.java:331)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
I think it could be caused by my log4j.properties file, in particular by ConversionPattern. Any idea on how to fix?
#Updated at Wed Sep 14 21:57:51 CEST 2011
#Wed Sep 14 21:57:51 CEST 2011
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.rootLogger=INFO, stdout
log4j.appender.R.File=yamweb.log
log4j.appender.R.MaxFileSize=1000KB
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.logger.yamweb=DEBUG
log4j.logger.org.springframework=INFO
log4j.logger.org.springframework.beans=DEBUG
log4j.logger.com.amazonaws=WARN
UPDATE: Actually, looking at the PatternLayout JavaDoc, I don't even mention a date format.
d Used to output the date of the logging event. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}. If no date format specifier is given then ISO8601 format is assumed.
I've added an explicit conversion pattern: %d{yyyy-MM-dd HH:mm:ss} [%t] %p %c - %m%n
-- looking at the log and I will let you know if it helps.
UPDATE 2: the problem didn't happen anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是一个旧线程,但我通过重新启动服务器解决了这个问题。是的,陈词滥调的答案,但值得一试
I know it's an old thread, but I fixed this problem by restarting the server. Yeah, cliche answer, but worth a try
看来这是一种非常罕见的情况。谷歌搜索错误发现了以下 2006 年的讨论,与类卸载有关:
http://comments.gmane.org/gmane.comp.jakarta。 log4j.user/13835
编辑:请参阅上面的问题以获取解决方案:
这似乎也适用于以下问题: NPE 与 Perf4j 和 Log4j。
It seems this is a very rare situation. Googling for the error turned up the following discussion from 2006, something to do with class un-loading:
http://comments.gmane.org/gmane.comp.jakarta.log4j.user/13835
EDIT: See question above for a solution:
This also seemed to work for the following question: NPE with Perf4j and Log4j.
我刚刚偶然发现了这个异常,通过从 portlet(或 servlet,无论什么)文件夹中删除
log4j.jar
解决了这个问题。I've just stumbled upon this exception, and it was solved by removing
log4j.jar
from the portlet (or servlet, whatever) folder.