View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package chapters.onJoran.helloWorld;
15  
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import ch.qos.logback.core.Context;
20  import ch.qos.logback.core.ContextBase;
21  import ch.qos.logback.core.joran.action.Action;
22  import ch.qos.logback.core.joran.spi.ElementSelector;
23  import ch.qos.logback.core.util.StatusPrinter;
24  import chapters.onJoran.SimpleConfigurator;
25  
26  /**
27   * 
28   * A hello world example using Joran.
29   * 
30   * @author Ceki Gulcu
31   */
32  public class HelloWorld {
33      public static void main(String[] args) throws Exception {
34          Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();
35  
36          // Associate "hello-world" pattern with HelloWorldAction
37          ruleMap.put(new ElementSelector("hello-world"), new HelloWorldAction());
38  
39          // Joran needs to work within a context.
40          Context context = new ContextBase();
41          SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
42          // link the configurator with its context
43          simpleConfigurator.setContext(context);
44  
45          simpleConfigurator.doConfigure(args[0]);
46          StatusPrinter.print(context);
47      }
48  }