使用 JRuby 进行非确定性日志记录 + Tomcat6 +日志4j
我正在使用 log4j 登录我的 JRuby on Rails 应用程序。每次我推出应用程序时,日志都会附加到不同的最终目的地。有时是catalina.out。有时是 localhost-date.log。有时是catalina-date.log。
我不太确定为什么每次都不一样。
我可以检查哪些事情来了解为什么日志在我的环境中如此不可靠?
I'm using log4j for logging in my JRuby on Rails application. Every single time I push the application out, logs are getting appended to different end destinations. Sometimes it's catalina.out. sometimes it's localhost-date.log. sometimes it's catalina-date.log.
I'm not really sure why it's not the same every single time.
what are some things I can check as to why logs are so unreliable in my environment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这确实很奇怪 - 您是否也偶然使用 Apache Commons Logging ?
这只是黑暗中的短暂,但每次我遇到一些奇怪的 log4j 和/或Commons Logging我立即回想起并重新审视后者的详细记录问题(请参阅在采用 commons-logging API 之前再三考虑,或者更全面的版本分类使用 Jakarta Commons Logging 时遇到的类加载器问题),在 delfuego 对 log4j 和线程上下文类加载器:
考虑到类加载器问题的本质,我可以想象它也会解决您的问题,即根据当前最终在日志记录中连接的类加载器,它可能会使用不同的日志记录属性搜索路径和各自的默认值,请参阅为什么 log4j 在 J2EE 或 WAR 中找不到我的属性文件应用程序?:
通过切换到 Simple Logging Facade for Java (SLF4J) 确实(顺便说一句,它恰好与 log4j 具有相同的作者,Ceki Gülcü),同样由 delfuego 建议:
最后,John 与 在 Tomcat jruby-rack 上为 Rails 3 应用程序使用 log4j 进行日志记录 似乎通过 SL4J 也是如此。
祝你好运!
This is pretty weird indeed - are you by chance using Apache Commons Logging as well?
It's just a short in the dark, but every time I experience something weird with log4j and/or Commons Logging I immediately recall and revisit the well documented problems with the latter specifically (see Think again before adopting the commons-logging API, or the even more comprehensive version Taxonomy of class loader problems encountered when using Jakarta Commons Logging), concisely summarized in delfuego's answer for log4j and the thread context classloader:
Given the very nature of the classloader issue, I could imagine it tripping your problem as well, i.e. depending on which classloader currently ended up wiring in your logging, it might use a different logging properties search path and respective defaults as well, see Why can't log4j find my properties file in a J2EE or WAR application?:
The mentioned problems are usually easy to remedy by switching to Simple Logging Facade for Java (SLF4J) indeed (which happens to have the same author as log4j btw., Ceki Gülcü), as likewise suggested by delfuego:
Finally, John's (as of today unresolved) adventure with Logging with log4j on tomcat jruby-rack for a Rails 3 application seems to hint on respective issues and a possible solution via SL4J as well.
Good luck!