001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.log;
016    
017    /**
018     * @author Brian Wing Shun Chan
019     */
020    public class LogWrapper implements Log {
021    
022            public LogWrapper(Log log) {
023                    _log = log;
024            }
025    
026            @Override
027            public void debug(Object msg) {
028                    try {
029                            _log.debug(msg);
030                    }
031                    catch (Exception e) {
032                            printMsg(msg);
033                    }
034            }
035    
036            @Override
037            public void debug(Object msg, Throwable t) {
038                    try {
039                            _log.debug(msg, t);
040                    }
041                    catch (Exception e) {
042                            printMsg(msg);
043                    }
044            }
045    
046            @Override
047            public void debug(Throwable t) {
048                    try {
049                            _log.debug(t);
050                    }
051                    catch (Exception e) {
052                            printMsg(t.getMessage());
053                    }
054            }
055    
056            @Override
057            public void error(Object msg) {
058                    try {
059                            _log.error(msg);
060                    }
061                    catch (Exception e) {
062                            printMsg(msg);
063                    }
064            }
065    
066            @Override
067            public void error(Object msg, Throwable t) {
068                    try {
069                            _log.error(msg, t);
070                    }
071                    catch (Exception e) {
072                            printMsg(msg);
073                    }
074            }
075    
076            @Override
077            public void error(Throwable t) {
078                    try {
079                            _log.error(t);
080                    }
081                    catch (Exception e) {
082                            printMsg(t.getMessage());
083                    }
084            }
085    
086            @Override
087            public void fatal(Object msg) {
088                    try {
089                            _log.fatal(msg);
090                    }
091                    catch (Exception e) {
092                            printMsg(msg);
093                    }
094            }
095    
096            @Override
097            public void fatal(Object msg, Throwable t) {
098                    try {
099                            _log.fatal(msg, t);
100                    }
101                    catch (Exception e) {
102                            printMsg(msg);
103                    }
104            }
105    
106            @Override
107            public void fatal(Throwable t) {
108                    try {
109                            _log.fatal(t);
110                    }
111                    catch (Exception e) {
112                            printMsg(t.getMessage());
113                    }
114            }
115    
116            public Log getWrappedLog() {
117                    return _log;
118            }
119    
120            @Override
121            public void info(Object msg) {
122                    try {
123                            _log.info(msg);
124                    }
125                    catch (Exception e) {
126                            printMsg(msg);
127                    }
128            }
129    
130            @Override
131            public void info(Object msg, Throwable t) {
132                    try {
133                            _log.info(msg, t);
134                    }
135                    catch (Exception e) {
136                            printMsg(msg);
137                    }
138            }
139    
140            @Override
141            public void info(Throwable t) {
142                    try {
143                            _log.info(t);
144                    }
145                    catch (Exception e) {
146                            printMsg(t.getMessage());
147                    }
148            }
149    
150            @Override
151            public boolean isDebugEnabled() {
152                    return _log.isDebugEnabled();
153            }
154    
155            @Override
156            public boolean isErrorEnabled() {
157                    return _log.isErrorEnabled();
158            }
159    
160            @Override
161            public boolean isFatalEnabled() {
162                    return _log.isFatalEnabled();
163            }
164    
165            @Override
166            public boolean isInfoEnabled() {
167                    return _log.isInfoEnabled();
168            }
169    
170            @Override
171            public boolean isTraceEnabled() {
172                    return _log.isTraceEnabled();
173            }
174    
175            @Override
176            public boolean isWarnEnabled() {
177                    return _log.isWarnEnabled();
178            }
179    
180            public void setLog(Log log) {
181                    _log = log;
182            }
183    
184            @Override
185            public void trace(Object msg) {
186                    try {
187                            _log.trace(msg);
188                    }
189                    catch (Exception e) {
190                            printMsg(msg);
191                    }
192            }
193    
194            @Override
195            public void trace(Object msg, Throwable t) {
196                    try {
197                            _log.trace(msg, t);
198                    }
199                    catch (Exception e) {
200                            printMsg(msg);
201                    }
202            }
203    
204            @Override
205            public void trace(Throwable t) {
206                    try {
207                            _log.trace(t);
208                    }
209                    catch (Exception e) {
210                            printMsg(t.getMessage());
211                    }
212            }
213    
214            @Override
215            public void warn(Object msg) {
216                    try {
217                            _log.warn(msg);
218                    }
219                    catch (Exception e) {
220                            printMsg(msg);
221                    }
222            }
223    
224            @Override
225            public void warn(Object msg, Throwable t) {
226                    try {
227                            _log.warn(msg, t);
228                    }
229                    catch (Exception e) {
230                            printMsg(msg);
231                    }
232            }
233    
234            @Override
235            public void warn(Throwable t) {
236                    try {
237                            _log.warn(t);
238                    }
239                    catch (Exception e) {
240                            printMsg(t.getMessage());
241                    }
242            }
243    
244            protected void printMsg(Object msg) {
245                    System.err.println(msg);
246            }
247    
248            private Log _log;
249    
250    }