2013-03-26 55 views
0

大家好日子。Webshpere和QOS logback:日志文件被锁定滚动

我无法解决一个问题:

我们使用的是WebSphere应用服务器为我们的应用程序,以及管理我们的日志文件“的logback”的日志框架。

看起来似乎很常见,但最近我们发现文件滚动的行为不可接受。 对于我们在WebSphere滚动日志文件上的第一次启动(按大小和按天计算)效果很好,但是当我们停止应用程序时 - 当前日志文件被java.exe(IBM WAS)进程锁定,当我们再次启动应用程序时 - 由于之前的锁定,滚动日志不起作用。当我看到文件通过窗口Unlocker我很惊讶 - 有2个进程锁定当前文件。如果我们停止应用程序并重新启动它 - 将会有3个java.exe锁定当前日志文件,尽管在任务管理器中只运行一个进程。有时我会在这种“测试”期间遇到OutOfMemory错误。

因此,我们在最后有非常大的日志文件。 (20GB和更多)

我发现了一些类似的问题,但与log4j滚动。没有任何解释为什么它是如此 - 只有一个像 - log4j不推荐用于websphere。

而且似乎问题不完全在“记录器”中。 那么,有没有人谁可以回答2个问题 -


  1. 为什么的WebSphere锁文件,而不是释放它,当应用程序已经已经停止???

  2. 如何在应用程序以正确方式停止时(不使用解锁器,任务管理器等作弊程序)释放(或者说WebSphere不锁定)日志文件锁定?


感谢关注...任何帮助,将不胜感激。


更新1:

最近我试着用小的web应用程序的logback与 - 和它的作品好 - 无需反复lockings。

而且我看着日志,当我们的大的应用程序被终止,并发现

27-03 05:59:39 [WebContainer : 7] INFO o.hibernate.impl.SessionFactoryImpl:close - closing

关闭,但没有关闭(停止应用程序的过程中在日志中唯一一个字符串)呢?我希望,我认为在一个正确的方式...

---- UPD 3

嗯...我已经花了很多时间部署在WebSphere定制WAR和我仍然无法找到有时WAS锁定日志文件的原因有时 - 不。

我简直不敢相信,我很惊讶,没有人谁面临着同样的烦恼

回答

1

本文不帮我 - http://logback.qos.ch/manual/jmxConfig.html 虽然我们并不在我们的应用使用任何JMXConfigurators ...

,所以我说在web.xml

<listener> 
    <listener-class>ru.fns.commonex.listener.CleanUpServletContextListener</listener-class> 
</listener> 

监听器有下面的代码:

@Override 
public void contextDestroyed(ServletContextEvent sce) { 
    log.debug("contextDestroyed({}) called.", sce); 
    deRegisterLog(); 
} 

/** 
* Avoiding memory leaks 
* 
* If your application is deployed in a web-server or an application server, 
* the registration of an JMXConfigurator instance creates a reference from the system class loader 
* into your application which will prevent it from being garbage collected when it is stopped or re-deployed, 
* resulting in a severe memory leak. 
* 
* Thus, unless your application is a standalone Java application, 
* you MUST unregister the JMXConfigurator instance from the JVM's Mbeans server. 
* Invoking the reset() method of the appropriate LoggerContext will automatically unregister any 
* JMXConfigurator instance. A good place to reset the logger context is in the contextDestroyed() 
* method of a javax.servlet.ServletContextListener. 
*/ 
private void deRegisterLog() { 
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); 
    log.info("Trying to stop logger factory {}", lc); 
    if (lc != null) { 
     lc.stop(); 
    } 
} 
+0

你究竟做了什么来解决这个问题?我一直在撞墙,一个星期试图处理同样的问题... – 2015-10-22 14:05:35

+1

托马斯,我发现了这个旧项目并更新了答案。请享用。 – Olegdelone 2015-10-25 10:19:30

相关问题