2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.remoting.logger;
19
20 import java.util.HashMap;
21 import java.util.Map;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /***
26 * <p>Implementation of {@link Logger} that interacts with the Apache Jakarta
27 * Commons Logging APIs.</p>
28 */
29 public final class CommonsLogger extends AbstractLogger {
30
31
32
33
34
35 /*** {@inheritDoc} */
36 public boolean isTraceEnabled(String name) {
37 return logger(name).isTraceEnabled();
38 }
39
40
41 /*** {@inheritDoc} */
42 public boolean isDebugEnabled(String name) {
43 return logger(name).isDebugEnabled();
44 }
45
46
47 /*** {@inheritDoc} */
48 public boolean isInfoEnabled(String name) {
49 return logger(name).isInfoEnabled();
50 }
51
52
53 /*** {@inheritDoc} */
54 public boolean isWarnEnabled(String name) {
55 return logger(name).isWarnEnabled();
56 }
57
58
59 /*** {@inheritDoc} */
60 public boolean isErrorEnabled(String name) {
61 return logger(name).isErrorEnabled();
62 }
63
64
65 /*** {@inheritDoc} */
66 public boolean isFatalEnabled(String name) {
67 return logger(name).isFatalEnabled();
68 }
69
70
71
72
73
74 /*** {@inheritDoc} */
75 public void trace(String name, String message,
76 Throwable exception, Object[] params) {
77 if (exception == null) {
78 logger(name).trace(message(message, params));
79 } else {
80 logger(name).trace(message(message, params), exception);
81 }
82 }
83
84
85 /*** {@inheritDoc} */
86 public void debug(String name, String message,
87 Throwable exception, Object[] params) {
88 if (exception == null) {
89 logger(name).debug(message(message, params));
90 } else {
91 logger(name).debug(message(message, params), exception);
92 }
93 }
94
95
96 /*** {@inheritDoc} */
97 public void info(String name, String message,
98 Throwable exception, Object[] params) {
99 if (exception == null) {
100 logger(name).info(message(message, params));
101 } else {
102 logger(name).info(message(message, params), exception);
103 }
104 }
105
106
107 /*** {@inheritDoc} */
108 public void warn(String name, String message,
109 Throwable exception, Object[] params) {
110 if (exception == null) {
111 logger(name).warn(message(message, params));
112 } else {
113 logger(name).warn(message(message, params), exception);
114 }
115 }
116
117
118 /*** {@inheritDoc} */
119 public void error(String name, String message,
120 Throwable exception, Object[] params) {
121 if (exception == null) {
122 logger(name).error(message(message, params));
123 } else {
124 logger(name).error(message(message, params), exception);
125 }
126 }
127
128
129 /*** {@inheritDoc} */
130 public void fatal(String name, String message,
131 Throwable exception, Object[] params) {
132 if (exception == null) {
133 logger(name).fatal(message(message, params));
134 } else {
135 logger(name).fatal(message(message, params), exception);
136 }
137 }
138
139
140
141
142
143 /***
144 * <p>Map of Commons Logging <code>Log</code> instances, keyed by name.</p>
145 */
146 private Map loggers = new HashMap();
147
148
149 /***
150 * <p>Return a Commons Logging <code>Log</code> instance for the specified
151 * logger name, creating a new one if necessary.</p>
152 *
153 * @param name Name of the requested logger
154 */
155 private synchronized Log logger(String name) {
156
157 Log logger = (Log) loggers.get(name);
158 if (logger == null) {
159 logger = LogFactory.getLog(name);
160 loggers.put(name, logger);
161 }
162 return logger;
163
164 }
165
166
167 }