|
44 | 44 | (name [_] "disabled") |
45 | 45 | (get-logger [_ _] disabled-logger))) |
46 | 46 |
|
| 47 | +(defn class-found? |
| 48 | + "Returns true if the Class associated with the given classname can be found |
| 49 | + using the context ClassLoader for the current thread." |
| 50 | + [name] |
| 51 | + (try |
| 52 | + (Class/forName name true (.. Thread currentThread getContextClassLoader)) |
| 53 | + true |
| 54 | + (catch ClassNotFoundException _ |
| 55 | + false))) |
| 56 | + |
| 57 | + |
47 | 58 | (defn slf4j-factory |
48 | 59 | "Returns a SLF4J-based implementation of the LoggerFactory protocol, or nil if |
49 | 60 | not available." |
50 | 61 | [] |
51 | | - (try |
52 | | - (Class/forName "org.slf4j.Logger") |
| 62 | + (when (class-found? "org.slf4j.Logger") |
53 | 63 | (eval |
54 | 64 | `(do |
55 | 65 | (extend org.slf4j.Logger |
|
88 | 98 | (name [_#] |
89 | 99 | "org.slf4j") |
90 | 100 | (get-logger [_# logger-ns#] |
91 | | - (org.slf4j.LoggerFactory/getLogger ^String (str logger-ns#)))))) |
92 | | - (catch Exception e nil))) |
| 101 | + (org.slf4j.LoggerFactory/getLogger ^String (str logger-ns#)))))))) |
93 | 102 |
|
94 | 103 | (defn cl-factory |
95 | 104 | "Returns a Commons Logging-based implementation of the LoggerFactory protocol, or |
96 | 105 | nil if not available." |
97 | 106 | [] |
98 | | - (try |
99 | | - (Class/forName "org.apache.commons.logging.Log") |
| 107 | + (when (class-found? "org.apache.commons.logging.Log") |
100 | 108 | (eval |
101 | 109 | `(do |
102 | 110 | (extend org.apache.commons.logging.Log |
|
134 | 142 | (name [_#] |
135 | 143 | "org.apache.commons.logging") |
136 | 144 | (get-logger [_# logger-ns#] |
137 | | - (org.apache.commons.logging.LogFactory/getLog (str logger-ns#)))))) |
138 | | - (catch Exception e nil))) |
| 145 | + (org.apache.commons.logging.LogFactory/getLog (str logger-ns#)))))))) |
139 | 146 |
|
140 | 147 | (defn log4j-factory |
141 | 148 | "Returns a Log4j-based implementation of the LoggerFactory protocol, or nil if |
142 | 149 | not available." |
143 | 150 | [] |
144 | | - (try |
145 | | - (Class/forName "org.apache.log4j.Logger") |
| 151 | + (when (class-found? "org.apache.log4j.Logger") |
146 | 152 | (eval |
147 | 153 | `(let [levels# {:trace org.apache.log4j.Level/TRACE |
148 | 154 | :debug org.apache.log4j.Level/DEBUG |
|
165 | 171 | (name [_#] |
166 | 172 | "org.apache.log4j") |
167 | 173 | (get-logger [_# logger-ns#] |
168 | | - (org.apache.log4j.Logger/getLogger ^String (str logger-ns#)))))) |
169 | | - (catch Exception e nil))) |
| 174 | + (org.apache.log4j.Logger/getLogger ^String (str logger-ns#)))))))) |
170 | 175 |
|
171 | 176 | (defn log4j2-factory |
172 | 177 | "Returns a Log4j2-based implementation of the LoggerFactory protocol, or nil if |
173 | 178 | not available." |
174 | 179 | [] |
175 | | - (try |
176 | | - (Class/forName "org.apache.logging.log4j.Logger") |
| 180 | + (when (class-found? "org.apache.logging.log4j.Logger") |
177 | 181 | (eval |
178 | 182 | `(let [levels# {:trace org.apache.logging.log4j.Level/TRACE |
179 | 183 | :debug org.apache.logging.log4j.Level/DEBUG |
|
202 | 206 | (name [_#] |
203 | 207 | "org.apache.logging.log4j") |
204 | 208 | (get-logger [_# logger-ns#] |
205 | | - (org.apache.logging.log4j.LogManager/getLogger ^String (str logger-ns#)))))) |
206 | | - (catch Exception e nil))) |
| 209 | + (org.apache.logging.log4j.LogManager/getLogger ^String (str logger-ns#)))))))) |
207 | 210 |
|
208 | 211 | (defn jul-factory |
209 | 212 | "Returns a java.util.logging-based implementation of the LoggerFactory protocol, |
210 | 213 | or nil if not available." |
211 | 214 | [] |
212 | | - (try |
213 | | - (Class/forName "java.util.logging.Logger") |
| 215 | + (when (class-found? "java.util.logging.Logger") |
214 | 216 | (eval |
215 | 217 | `(let [levels# {:trace java.util.logging.Level/FINEST |
216 | 218 | :debug java.util.logging.Level/FINE |
|
234 | 236 | (name [_#] |
235 | 237 | "java.util.logging") |
236 | 238 | (get-logger [_# logger-ns#] |
237 | | - (java.util.logging.Logger/getLogger (str logger-ns#)))))) |
238 | | - (catch Exception e nil))) |
| 239 | + (java.util.logging.Logger/getLogger (str logger-ns#)))))))) |
239 | 240 |
|
240 | 241 | (defn find-factory |
241 | 242 | "Returns the first non-nil value from slf4j-factory, cl-factory, |
|
0 commit comments