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