Reputation: 199
Good day everyone.
I can't resolve the next problem:
We are using WebSphere app server for our application, and "logback" logging framework for managing our log files.
Seemed everithing was working fine but recently we detected unacceptable behavior of file rolling. For the first starting of our application on WebSphere rolling log files (by size and by days) works good, but when we stop application - current log file is locked by java.exe(IBM WAS) process and when we start application over again - rolling logs does not work because of previous locking. When I looked on the file throu windows Unlocker i was surprised - there were 2 processes which locks current file. And if we stop app and start it again - there will be 3 java.exe that lock current log file, although in the task manager running only one process. Sometimes I catch OutOfMemory error during such "testing".
So that, we have very big log file at the end. (20GB and more)
I've found some similar problems but with log4j rolling. And there are no any explanation why it was so - just one was like - log4j is not recommended for websphere.
And seems problem not exactly in "logger" at all. So, is there anybody who could answer 2 questions -
Why does WebSphere lock file and not release it, when application has been already stopped???
How to release (or say to WebSphere not to lock) locking of the log file when application is stopped in a right way(without using cheats like Unlocker, Task Manager, etc.)?
Thanks for attention... any help would be appreciated.
UPDATE 1:
Recently I tried to use small web app with logback - and it works good - with no repeatedly lockings.
Also I looked into the logs, when our big application is stopped, and found this (the only one string in a log during stopping the application)
27-03 05:59:39 [WebContainer : 7] INFO o.hibernate.impl.SessionFactoryImpl:close - closing
closing but not closed ? I hope I think in a right way...
----UPD 3
Hmm... I've spent a lot of time deploying custom WARs on websphere and still i can't find out the reason why sometimes WAS locks logs files and sometimes - doesn't.
I can't believe and i'm surprised that there is no people who faced with the same troubles
Upvotes: 0
Views: 1259
Reputation: 199
This article does help me - http://logback.qos.ch/manual/jmxConfig.html although we do not use any JMXConfigurators in our apps ...
So i added in web.xml
<listener>
<listener-class>ru.fns.commonex.listener.CleanUpServletContextListener</listener-class>
</listener>
Listener has next code:
@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();
}
}
Upvotes: 1