1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.osgi.boot.logback.internal;
20
21 import java.io.File;
22 import java.util.Map;
23
24 import org.slf4j.LoggerFactory;
25
26 import ch.qos.logback.classic.LoggerContext;
27 import ch.qos.logback.classic.joran.JoranConfigurator;
28 import ch.qos.logback.core.joran.JoranConfiguratorBase;
29 import ch.qos.logback.core.joran.spi.JoranException;
30 import ch.qos.logback.core.util.StatusPrinter;
31
32
33
34
35
36
37 public class LogbackInitializer {
38
39
40
41
42 private static boolean isPDEDevelopment()
43 {
44 String eclipseCommands = System.getProperty("eclipse.commands");
45
46 return eclipseCommands != null && eclipseCommands.indexOf("-dev") != -1
47 && (eclipseCommands.indexOf("-dev\n") != -1
48 || eclipseCommands.indexOf("-dev\r") != -1
49 || eclipseCommands.indexOf("-dev ") != -1);
50 }
51
52
53
54
55
56
57
58 public static void processFilesInResourcesFolder(File jettyHome, Map<String,File> files)
59 {
60 String logbackConf = System.getProperty("logback.configurationFile");
61 if (logbackConf != null)
62 {
63 File confFile = new File(logbackConf);
64 if (confFile.exists())
65 {
66
67 return;
68 }
69 }
70
71 File logConf = isPDEDevelopment() ? files.get("logback-dev.xml") : null;
72 if (logConf == null)
73 {
74 logConf = files.get("logback-test.xml");
75 }
76 if (logConf == null)
77 {
78 logConf = files.get("logback.xml");
79 }
80 if (logConf == null)
81 {
82 return;
83 }
84
85 LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
86
87 try
88 {
89 JoranConfiguratorBase configurator = new JoranConfigurator();
90 configurator.setContext(lc);
91 lc.reset();
92 configurator.doConfigure(logConf.getAbsoluteFile().getAbsolutePath());
93 }
94 catch (JoranException je)
95 {
96 je.printStackTrace();
97 }
98 StatusPrinter.printIfErrorsOccured(lc);
99
100 }
101
102 }