
I have a weird problem in my multi-threaded application on Solaris but not on Windows XP. Basically I have a bunch of tasks that are executed by the ThreadPoolExecutor and when the last task is executed the ThreadPoolExecutor is required to run a shutdown task (Runnable) provided to the executor by the main thread. The problem is, the log messages from this shutdown task never get flushed to the log file but it sure gets executed. I even added the LoggerContext.stop() to no effect. I am completely baffled as to why it is not flushing, any pointers/ideas will be much appreciated. Thanks. System Spec ========== System = SunOS Node = jdcsj002 Release = 5.10 KernelID = Generic_137137-09 Machine = sun4u -Harish

Hello Harish, What types of appenders are you using? Also, if some code shuts down logback before the shutdown hook gets executed, any code within the shutdown hook will be using closed appenders. The different behavior on Windows and SunOS is quite baffling though. HTH, Harish Krishnaswamy wrote:
I have a weird problem in my multi-threaded application on Solaris but not on Windows XP.
Basically I have a bunch of tasks that are executed by the ThreadPoolExecutor and when the last task is executed the ThreadPoolExecutor is required to run a shutdown task (Runnable) provided to the executor by the main thread. The problem is, the log messages from this shutdown task never get flushed to the log file but it sure gets executed. I even added the LoggerContext.stop() to no effect. I am completely baffled as to why it is not flushing, any pointers/ideas will be much appreciated. Thanks.
System Spec ========== System = SunOS Node = jdcsj002 Release = 5.10 KernelID = Generic_137137-09 Machine = sun4u
-Harish
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Hi Ceki, I am using the RollingFileAppender and the SMTPAppender. And actually I get the email but its just not going to the file which makes me believe that its just not getting flushed. I am listing the shutdown task and the logback config. I appreciate the help! <configuration> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>file.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>file-%d{yyyy-MM-dd}.log</FileNamePattern> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date %level [%thread] [%logger{0}] %msg%n%ex</Pattern> </layout> </appender> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%msg%n</Pattern> </layout> </appender> <root> <level value="info" /> <appender-ref ref="FILE" /> <!-- appender-ref ref="STDOUT" /--> </root> <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> <SMTPHost>smtp.gmail.com</SMTPHost> <SMTPPort>465</SMTPPort> <SSL>true</SSL> <Username>user@gmail.com</Username> <Password>pwd</Password> <To>id@domain.com</To> <From>name@gmail.com</From> <Subject>Stats - %m</Subject> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%msg%n</Pattern> </layout> </appender> <logger name="email"> <level value="info" /> <appender-ref ref="EMAIL" /> </logger> </configuration> return new Runnable() { public void run() { // If another thread cleared this task then return if (_shutdownTask == null) return; _shutdownTask = null; _logger.info("Importer shutting down..."); // Log stats if (_piLoader != null) { PiStats stats = _ctx.get(PiStats.class); Logger emailLogger = LoggerFactory.getLogger("email"); emailLogger.info(stats.toString()); String hostName = null; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { hostName = "Unknown host"; } // This will trigger the email // user.name and host will indicate the environment this message is coming from emailLogger.error(System.getProperty("user.name") + " - " + hostName); } // Cleanup state // This will give any open SqlSessions a chance to finalize // System.runFinalization(); _runningToken.delete(); _logger.info("Importer shutdown complete."); LoggerContext lCtx = (LoggerContext) LoggerFactory.getILoggerFactory(); lCtx.stop(); } }; -Harish On Thu, Feb 5, 2009 at 2:57 PM, Ceki Gulcu <ceki@qos.ch> wrote:
Hello Harish,
What types of appenders are you using? Also, if some code shuts down logback before the shutdown hook gets executed, any code within the shutdown hook will be using closed appenders.
The different behavior on Windows and SunOS is quite baffling though.
HTH,
Harish Krishnaswamy wrote:
I have a weird problem in my multi-threaded application on Solaris but not on Windows XP.
Basically I have a bunch of tasks that are executed by the ThreadPoolExecutor and when the last task is executed the ThreadPoolExecutor is required to run a shutdown task (Runnable) provided to the executor by the main thread. The problem is, the log messages from this shutdown task never get flushed to the log file but it sure gets executed. I even added the LoggerContext.stop() to no effect. I am completely baffled as to why it is not flushing, any pointers/ideas will be much appreciated. Thanks.
System Spec ========== System = SunOS Node = jdcsj002 Release = 5.10 KernelID = Generic_137137-09 Machine = sun4u
-Harish
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

I have ran HarishMain application using the logback.xml included in the attachments. I am seeing all messages as expected. Could you please run the tests on your side and see if it works for you? Harish Krishnaswamy wrote:
Hi Ceki,
I am using the RollingFileAppender and the SMTPAppender. And actually I get the email but its just not going to the file which makes me believe that its just not getting flushed. I am listing the shutdown task and the logback config. I appreciate the help!
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch package ch.qos.logback.classic; import java.net.InetAddress; import java.net.UnknownHostException; import org.slf4j.LoggerFactory; public class HarishMain { public static void main(String[] args) throws InterruptedException { org.slf4j.Logger logger = LoggerFactory.getLogger(HarishMain.class); logger.info("Harish"); Thread.sleep(3000); Runtime runtime = Runtime.getRuntime(); runtime.addShutdownHook(new Thread(new HarishRunnable())); } static class HarishRunnable implements Runnable { org.slf4j.Logger _logger = LoggerFactory.getLogger(this.getClass()); public void run() { _logger.info("Importer shutting down..."); org.slf4j.Logger emailLogger = LoggerFactory.getLogger("email"); emailLogger.info("status"); String hostName = null; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { hostName = "Unknown host"; } emailLogger.error(System.getProperty("user.name") + " - " + hostName); _logger.info("Importer shutdown complete."); LoggerContext lCtx = (LoggerContext) LoggerFactory.getILoggerFactory(); lCtx.stop(); } } }

This is one of the weirdest problems I have seen :) Your test files worked fine as-is, so I modified it to closely resemble the original codebase and it still worked, so I went back to playing with the original codebase and all of sudden after midnight it started working and it still works now with the original code after backing out all my patches for this problem. One thing I noticed though - the code is running a bit slower now than it was this morning, probably due to another process on the box, but I still can't explain the behavior. I will have to see what happens tomorrow :) But, thanks again for your help. -Harish 2009/2/5 Ceki Gulcu <ceki@qos.ch>
I have ran HarishMain application using the logback.xml included in the attachments. I am seeing all messages as expected. Could you please run the tests on your side and see if it works for you?
Harish Krishnaswamy wrote:
Hi Ceki,
I am using the RollingFileAppender and the SMTPAppender. And actually I get the email but its just not going to the file which makes me believe that its just not getting flushed. I am listing the shutdown task and the logback config. I appreciate the help!
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch
package ch.qos.logback.classic;
import java.net.InetAddress; import java.net.UnknownHostException;
import org.slf4j.LoggerFactory;
public class HarishMain {
public static void main(String[] args) throws InterruptedException {
org.slf4j.Logger logger = LoggerFactory.getLogger(HarishMain.class); logger.info("Harish"); Thread.sleep(3000); Runtime runtime = Runtime.getRuntime(); runtime.addShutdownHook(new Thread(new HarishRunnable())); }
static class HarishRunnable implements Runnable { org.slf4j.Logger _logger = LoggerFactory.getLogger(this.getClass());
public void run() { _logger.info("Importer shutting down...");
org.slf4j.Logger emailLogger = LoggerFactory.getLogger("email"); emailLogger.info("status");
String hostName = null;
try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { hostName = "Unknown host"; }
emailLogger.error(System.getProperty("user.name") + " - " + hostName);
_logger.info("Importer shutdown complete.");
LoggerContext lCtx = (LoggerContext) LoggerFactory.getILoggerFactory(); lCtx.stop(); } }
}
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
participants (2)
-
Ceki Gulcu
-
Harish Krishnaswamy