View Javadoc

1   /**
2    * Logback: the reliable, fast and flexible logging library for Java.
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 chapter10.helloWorld;
12  
13  import java.util.HashMap;
14  import java.util.Map;
15  
16  import ch.qos.logback.core.Context;
17  import ch.qos.logback.core.ContextBase;
18  import ch.qos.logback.core.joran.action.Action;
19  import ch.qos.logback.core.joran.spi.Pattern;
20  import ch.qos.logback.core.util.StatusPrinter;
21  import chapter10.SimpleConfigurator;
22  
23  /**
24   * 
25   * A hello world example using Joran.
26   * 
27   * @author Ceki Gulcu
28   */
29  public class HelloWorld {
30    public static void main(String[] args) throws Exception {
31      Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>();
32  
33      // Associate "hello-world" pattern with HelloWorldAction
34      ruleMap.put(new Pattern("hello-world"), new HelloWorldAction());
35  
36      // Joran needs to work within a context.
37      Context context = new ContextBase();
38      SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
39      // link the configurator with its context
40      simpleConfigurator.setContext(context);
41  
42      simpleConfigurator.doConfigure(args[0]);
43      StatusPrinter.print(context);
44    }
45  }