1
2
3
4
5
6
7
8
9
10 package chapter4;
11
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import org.slf4j.MDC;
15
16 import ch.qos.logback.classic.LoggerContext;
17 import ch.qos.logback.classic.joran.JoranConfigurator;
18 import ch.qos.logback.core.joran.spi.JoranException;
19 import ch.qos.logback.core.util.StatusPrinter;
20 import chapter4.sub.sample.Bar;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class ConfigurationTester {
36
37 public static void main(String[] args) throws InterruptedException {
38 Logger logger = (Logger) LoggerFactory.getLogger(ConfigurationTester.class);
39 LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
40
41 try {
42 JoranConfigurator configurator = new JoranConfigurator();
43 configurator.setContext(lc);
44 lc.reset();
45 configurator.doConfigure(args[0]);
46 } catch (JoranException je) {
47 je.printStackTrace();
48 }
49
50
51 StatusPrinter.print(lc.getStatusManager());
52
53 logger.debug("**Hello {}", new Bar());
54 MDC.put("testKey", "testValueFromMDC");
55 MDC.put("testKey2", "value2");
56 for (int i = 0; i < 10; i++) {
57 logger.debug("logging statement " + i);
58 Thread.sleep(1000);
59 }
60 Bar bar = new Bar();
61 bar.createLoggingRequest();
62 }
63 }