View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2009, 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 chapter11;
11  
12  import org.slf4j.Logger;
13  import org.slf4j.LoggerFactory;
14  
15  import ch.qos.logback.classic.LoggerContext;
16  import ch.qos.logback.classic.joran.JoranConfigurator;
17  import ch.qos.logback.core.joran.spi.JoranException;
18  import ch.qos.logback.core.util.StatusPrinter;
19  
20  /**
21   * A minimal application making use of logback-classic. It uses the
22   * configuration file logback-trivial.xml which makes use of
23   * TivialLogbackAppender.
24   * 
25   * @author Ceki Gülcü
26   */
27  public class LogbackMain {
28  
29    static Logger logger = LoggerFactory.getLogger(LogbackMain.class);
30  
31    public static void main(String[] args) throws JoranException {
32      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
33  
34      JoranConfigurator configurator = new JoranConfigurator();
35      configurator.setContext(lc);
36      lc.reset();
37      configurator.doConfigure("src/main/java/chapter11/logback-trivial.xml");
38      StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
39      
40      
41      logger.debug("Hello world");
42    }
43  
44  }