[logback-user] Flushing problem

Harish Krishnaswamy harishkswamy at gmail.com
Thu Feb 5 21:27:45 CET 2009


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 at gmail.com</Username>
        <Password>pwd</Password>

        <To>id at domain.com</To>
        <From>name at 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 at 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 at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20090205/fb4a7b85/attachment-0001.htm>


More information about the Logback-user mailing list