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.receivers.socket;
15  
16  import org.slf4j.LoggerFactory;
17  
18  import ch.qos.logback.classic.LoggerContext;
19  import ch.qos.logback.classic.joran.JoranConfigurator;
20  
21  /**
22   * This application loads a configuration containing a 
23   * receiver component and logs events received from the remote
24   * appender according to the local configuration.
25   */
26  public class ReceiverExample {
27  
28      static void usage(String msg) {
29          System.err.println(msg);
30          System.err.println("Usage: java " + ReceiverExample.class.getName() + " configFile\n" + "   configFile a logback configuration file"
31                          + "   in XML format.");
32          System.exit(1);
33      }
34  
35      static public void main(String[] args) throws Exception {
36          if (args.length != 1) {
37              usage("Wrong number of arguments.");
38          }
39  
40          String configFile = args[0];
41  
42          if (configFile.endsWith(".xml")) {
43              LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
44              lc.reset();
45              JoranConfigurator configurator = new JoranConfigurator();
46              configurator.setContext(lc);
47              configurator.doConfigure(configFile);
48          }
49  
50          Thread.sleep(Long.MAX_VALUE);
51      }
52  
53  }