1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.test.spring.log4j;
17
18 import org.mortbay.log.Log;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.springframework.util.Log4jConfigurer;
22
23 import java.io.FileNotFoundException;
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public final class KSLog4JConfigurer {
38
39
40
41
42 public static final String LOG4J_PROPERTIES_REFRESH = "log4j.properties.refresh";
43
44
45
46
47 public static final String LOG4J_PROPERTIES = "log4j.properties";
48
49 private KSLog4JConfigurer() {
50
51 }
52
53
54
55
56
57
58
59
60
61
62 public static final Logger getLogger(Class<?> clazz) {
63
64 return getLogger(clazz, LOG4J_PROPERTIES, LOG4J_PROPERTIES_REFRESH);
65 }
66
67
68
69
70
71
72
73
74
75
76 public static final Logger getLogger(Class<?> clazz,
77 String systemPropertyName, String refreshPropertyName) {
78
79 String log4jconfig = System.getProperty(systemPropertyName);
80
81 Long refreshInterval;
82
83 try {
84 refreshInterval = Long.valueOf(System.getProperty(refreshPropertyName));
85 } catch (NumberFormatException e1) {
86 refreshInterval = null;
87 }
88
89 boolean exception = false;
90
91 if (log4jconfig != null) {
92 try {
93
94 if (refreshInterval != null) {
95 Log4jConfigurer.initLogging(log4jconfig, refreshInterval);
96 }
97 else {
98 Log4jConfigurer.initLogging(log4jconfig);
99 }
100
101 } catch (FileNotFoundException e) {
102
103 exception = true;
104 }
105 }
106
107 Logger log = LoggerFactory.getLogger(clazz);
108
109 if (log.isDebugEnabled()) {
110
111 if (refreshInterval != null)
112 log.debug(String.format("Log4jConfigurer.initLogging(log4jconfig=%s, refreshInterval=%s)", log4jconfig, refreshInterval));
113 else
114 log.debug(String.format("Log4jConfigurer.initLogging(log4jconfig=%s)", log4jconfig));
115
116 }
117
118 if (exception)
119 log.error("Missing Configuration File: " + log4jconfig
120 + ", For system property: " + systemPropertyName);
121
122 return log;
123
124 }
125
126 }