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 setLogWrapperClassName(String className) {
186                    _log.setLogWrapperClassName(className);
187            }
188    
189            @Override
190            public void trace(Object msg) {
191                    try {
192                            _log.trace(msg);
193                    }
194                    catch (Exception e) {
195                            printMsg(msg);
196                    }
197            }
198    
199            @Override
200            public void trace(Object msg, Throwable t) {
201                    try {
202                            _log.trace(msg, t);
203                    }
204                    catch (Exception e) {
205                            printMsg(msg);
206                    }
207            }
208    
209            @Override
210            public void trace(Throwable t) {
211                    try {
212                            _log.trace(t);
213                    }
214                    catch (Exception e) {
215                            printMsg(t.getMessage());
216                    }
217            }
218    
219            @Override
220            public void warn(Object msg) {
221                    try {
222                            _log.warn(msg);
223                    }
224                    catch (Exception e) {
225                            printMsg(msg);
226                    }
227            }
228    
229            @Override
230            public void warn(Object msg, Throwable t) {
231                    try {
232                            _log.warn(msg, t);
233                    }
234                    catch (Exception e) {
235                            printMsg(msg);
236                    }
237            }
238    
239            @Override
240            public void warn(Throwable t) {
241                    try {
242                            _log.warn(t);
243                    }
244                    catch (Exception e) {
245                            printMsg(t.getMessage());
246                    }
247            }
248    
249            protected void printMsg(Object msg) {
250                    System.err.println(msg);
251            }
252    
253            private Log _log;
254    
255    }