View Javadoc

1   package chapter5;
2   
3   import org.slf4j.Logger;
4   import org.slf4j.LoggerFactory;
5   
6   import ch.qos.logback.classic.LoggerContext;
7   import ch.qos.logback.classic.joran.JoranConfigurator;
8   import ch.qos.logback.core.joran.spi.JoranException;
9   import ch.qos.logback.core.util.StatusPrinter;
10  
11  public class ExceptionEvaluatorExample {
12  
13    public static void main(String[] args) {
14      Logger logger = LoggerFactory.getLogger(ExceptionEvaluatorExample.class);
15      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
16  
17      try {
18        JoranConfigurator configurator = new JoranConfigurator();
19        configurator.setContext(lc);
20        lc.shutdownAndReset();
21        configurator.doConfigure(args[0]);
22      } catch (JoranException je) {
23        StatusPrinter.print(lc);
24      }
25      for (int i = 0; i < 5; i++) {
26        if (i == 3) {
27          logger.debug("logging statement " + i, new TestException(
28              "do not display this"));
29        } else {
30          logger.debug("logging statement " + i, new Exception("display"));
31        }
32      }
33    }
34  }