1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.jcl;
18
19 import java.io.IOException;
20 import java.util.concurrent.ConcurrentHashMap;
21 import java.util.concurrent.ConcurrentMap;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogConfigurationException;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.logging.log4j.spi.LoggerAdapter;
27
28
29
30
31
32 public class LogFactoryImpl extends LogFactory {
33
34 private final LoggerAdapter<Log> adapter = new LogAdapter();
35
36 private final ConcurrentMap<String, Object> attributes = new ConcurrentHashMap<String, Object>();
37
38 @Override
39 public Log getInstance(final String name) throws LogConfigurationException {
40 return adapter.getLogger(name);
41 }
42
43 @Override
44 public Object getAttribute(final String name) {
45 return attributes.get(name);
46 }
47
48 @Override
49 public String[] getAttributeNames() {
50 return attributes.keySet().toArray(new String[attributes.size()]);
51 }
52
53 @Override
54 public Log getInstance(@SuppressWarnings("rawtypes") final Class clazz) throws LogConfigurationException {
55 return getInstance(clazz.getName());
56 }
57
58
59
60
61
62 @Override
63 public void release() {
64 try {
65 adapter.close();
66 } catch (final IOException ignored) {
67 }
68 }
69
70 @Override
71 public void removeAttribute(final String name) {
72 attributes.remove(name);
73 }
74
75 @Override
76 public void setAttribute(final String name, final Object value) {
77 if (value != null) {
78 attributes.put(name, value);
79 } else {
80 removeAttribute(name);
81 }
82 }
83
84 }