1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.log;
24  
25  /**
26   * <a href="LogWrapper.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class LogWrapper implements Log {
31  
32      public LogWrapper(Log log) {
33          _log = log;
34      }
35  
36      public void setLog(Log log) {
37          _log = log;
38      }
39  
40      public void debug(Object msg) {
41          try {
42              _log.debug(msg);
43          }
44          catch (Exception e) {
45              printMsg(msg);
46          }
47      }
48  
49      public void debug(Throwable t) {
50          try {
51              _log.debug(t);
52          }
53          catch (Exception e) {
54              printMsg(t.getMessage());
55          }
56      }
57  
58      public void debug(Object msg, Throwable t) {
59          try {
60              _log.debug(msg, t);
61          }
62          catch (Exception e) {
63              printMsg(msg);
64          }
65      }
66  
67      public void error(Object msg) {
68          try {
69              _log.error(msg);
70          }
71          catch (Exception e) {
72              printMsg(msg);
73          }
74      }
75  
76      public void error(Throwable t) {
77          try {
78              _log.error(t);
79          }
80          catch (Exception e) {
81              printMsg(t.getMessage());
82          }
83      }
84  
85      public void error(Object msg, Throwable t) {
86          try {
87              _log.error(msg, t);
88          }
89          catch (Exception e) {
90              printMsg(msg);
91          }
92      }
93  
94      public void fatal(Object msg) {
95          try {
96              _log.fatal(msg);
97          }
98          catch (Exception e) {
99              printMsg(msg);
100         }
101     }
102 
103     public void fatal(Throwable t) {
104         try {
105             _log.fatal(t);
106         }
107         catch (Exception e) {
108             printMsg(t.getMessage());
109         }
110     }
111 
112     public void fatal(Object msg, Throwable t) {
113         try {
114             _log.fatal(msg, t);
115         }
116         catch (Exception e) {
117             printMsg(msg);
118         }
119     }
120 
121     public void info(Object msg) {
122         try {
123             _log.info(msg);
124         }
125         catch (Exception e) {
126             printMsg(msg);
127         }
128     }
129 
130     public void info(Throwable t) {
131         try {
132             _log.info(t);
133         }
134         catch (Exception e) {
135             printMsg(t.getMessage());
136         }
137     }
138 
139     public void info(Object msg, Throwable t) {
140         try {
141             _log.info(msg, t);
142         }
143         catch (Exception e) {
144             printMsg(msg);
145         }
146     }
147 
148     public boolean isDebugEnabled() {
149         return _log.isDebugEnabled();
150     }
151 
152     public boolean isErrorEnabled() {
153         return _log.isErrorEnabled();
154     }
155 
156     public boolean isFatalEnabled() {
157         return _log.isFatalEnabled();
158     }
159 
160     public boolean isInfoEnabled() {
161         return _log.isInfoEnabled();
162     }
163 
164     public boolean isTraceEnabled() {
165         return _log.isTraceEnabled();
166     }
167 
168     public boolean isWarnEnabled() {
169         return _log.isWarnEnabled();
170     }
171 
172     public void trace(Object msg) {
173         try {
174             _log.trace(msg);
175         }
176         catch (Exception e) {
177             printMsg(msg);
178         }
179     }
180 
181     public void trace(Throwable t) {
182         try {
183             _log.trace(t);
184         }
185         catch (Exception e) {
186             printMsg(t.getMessage());
187         }
188     }
189 
190     public void trace(Object msg, Throwable t) {
191         try {
192             _log.trace(msg, t);
193         }
194         catch (Exception e) {
195             printMsg(msg);
196         }
197     }
198 
199     public void warn(Object msg) {
200         try {
201             _log.warn(msg);
202         }
203         catch (Exception e) {
204             printMsg(msg);
205         }
206     }
207 
208     public void warn(Throwable t) {
209         try {
210             _log.warn(t);
211         }
212         catch (Exception e) {
213             printMsg(t.getMessage());
214         }
215     }
216 
217     public void warn(Object msg, Throwable t) {
218         try {
219             _log.warn(msg, t);
220         }
221         catch (Exception e) {
222             printMsg(msg);
223         }
224     }
225 
226     protected void printMsg(Object msg) {
227         System.err.println(msg);
228     }
229 
230     private Log _log;
231 
232 }