View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  
11  package chapter3;
12  
13  import org.slf4j.Logger;
14  import org.slf4j.LoggerFactory;
15  
16  import ch.qos.logback.classic.LoggerContext;
17  import ch.qos.logback.classic.joran.JoranConfigurator;
18  import ch.qos.logback.core.joran.spi.JoranException;
19  import ch.qos.logback.core.util.StatusPrinter;
20  
21  public class MyApp2 {
22    final static Logger logger = LoggerFactory.getLogger(MyApp2.class);
23  
24    public static void main(String[] args) {
25      // assume logback is in use
26      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
27      
28  
29      try {
30        JoranConfigurator configurator = new JoranConfigurator();
31        configurator.setContext(lc);
32        lc.shutdownAndReset();
33        configurator.doConfigure(args[0]);
34      } catch (JoranException je) {
35        StatusPrinter.print(lc);
36      }
37  
38      logger.info("Entering application.");
39  
40      Foo foo = new Foo();
41      foo.doIt();
42      logger.info("Exiting application.");
43    }
44  }