View Javadoc

1   /**
2    * Logback: the generic, reliable, 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  package chapter2;
11  
12  //Import SLF4J classes.
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 MyAppWithConfigFile {
22  
23    public static void main(String[] args) {
24      Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
25      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
26  
27      try {
28        JoranConfigurator configurator = new JoranConfigurator();
29        lc.reset();
30        configurator.setContext(lc);
31        configurator.doConfigure(args[0]);
32      } catch (JoranException je) {
33        StatusPrinter.print(lc.getStatusManager());
34      }
35      logger.info("Entering application.");
36      Bar bar = new Bar();
37      bar.doIt();
38      logger.info("Exiting application.");
39  
40    }
41  }