1
2
3
4
5
6
7
8
9
10
11
12
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
23
24
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 }