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();
    }
  }

}
<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_HHmmss}.log</FileNamePattern>
    </rollingPolicy>

    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%date %level [%thread] [%logger{0}] %msg%n%ex</Pattern>
    </layout>
  </appender>


  <root level="info">
    <appender-ref ref="FILE" />
  </root>

</configuration>
_______________________________________________
Logback-user mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-user

Reply via email to