001    /**
002     * Copyright (c) 2000-2010 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            public void setLog(Log log) {
027                    _log = log;
028            }
029    
030            public void debug(Object msg) {
031                    try {
032                            _log.debug(msg);
033                    }
034                    catch (Exception e) {
035                            printMsg(msg);
036                    }
037            }
038    
039            public void debug(Throwable t) {
040                    try {
041                            _log.debug(t);
042                    }
043                    catch (Exception e) {
044                            printMsg(t.getMessage());
045                    }
046            }
047    
048            public void debug(Object msg, Throwable t) {
049                    try {
050                            _log.debug(msg, t);
051                    }
052                    catch (Exception e) {
053                            printMsg(msg);
054                    }
055            }
056    
057            public void error(Object msg) {
058                    try {
059                            _log.error(msg);
060                    }
061                    catch (Exception e) {
062                            printMsg(msg);
063                    }
064            }
065    
066            public void error(Throwable t) {
067                    try {
068                            _log.error(t);
069                    }
070                    catch (Exception e) {
071                            printMsg(t.getMessage());
072                    }
073            }
074    
075            public void error(Object msg, Throwable t) {
076                    try {
077                            _log.error(msg, t);
078                    }
079                    catch (Exception e) {
080                            printMsg(msg);
081                    }
082            }
083    
084            public void fatal(Object msg) {
085                    try {
086                            _log.fatal(msg);
087                    }
088                    catch (Exception e) {
089                            printMsg(msg);
090                    }
091            }
092    
093            public void fatal(Throwable t) {
094                    try {
095                            _log.fatal(t);
096                    }
097                    catch (Exception e) {
098                            printMsg(t.getMessage());
099                    }
100            }
101    
102            public void fatal(Object msg, Throwable t) {
103                    try {
104                            _log.fatal(msg, t);
105                    }
106                    catch (Exception e) {
107                            printMsg(msg);
108                    }
109            }
110    
111            public void info(Object msg) {
112                    try {
113                            _log.info(msg);
114                    }
115                    catch (Exception e) {
116                            printMsg(msg);
117                    }
118            }
119    
120            public void info(Throwable t) {
121                    try {
122                            _log.info(t);
123                    }
124                    catch (Exception e) {
125                            printMsg(t.getMessage());
126                    }
127            }
128    
129            public void info(Object msg, Throwable t) {
130                    try {
131                            _log.info(msg, t);
132                    }
133                    catch (Exception e) {
134                            printMsg(msg);
135                    }
136            }
137    
138            public boolean isDebugEnabled() {
139                    return _log.isDebugEnabled();
140            }
141    
142            public boolean isErrorEnabled() {
143                    return _log.isErrorEnabled();
144            }
145    
146            public boolean isFatalEnabled() {
147                    return _log.isFatalEnabled();
148            }
149    
150            public boolean isInfoEnabled() {
151                    return _log.isInfoEnabled();
152            }
153    
154            public boolean isTraceEnabled() {
155                    return _log.isTraceEnabled();
156            }
157    
158            public boolean isWarnEnabled() {
159                    return _log.isWarnEnabled();
160            }
161    
162            public void trace(Object msg) {
163                    try {
164                            _log.trace(msg);
165                    }
166                    catch (Exception e) {
167                            printMsg(msg);
168                    }
169            }
170    
171            public void trace(Throwable t) {
172                    try {
173                            _log.trace(t);
174                    }
175                    catch (Exception e) {
176                            printMsg(t.getMessage());
177                    }
178            }
179    
180            public void trace(Object msg, Throwable t) {
181                    try {
182                            _log.trace(msg, t);
183                    }
184                    catch (Exception e) {
185                            printMsg(msg);
186                    }
187            }
188    
189            public void warn(Object msg) {
190                    try {
191                            _log.warn(msg);
192                    }
193                    catch (Exception e) {
194                            printMsg(msg);
195                    }
196            }
197    
198            public void warn(Throwable t) {
199                    try {
200                            _log.warn(t);
201                    }
202                    catch (Exception e) {
203                            printMsg(t.getMessage());
204                    }
205            }
206    
207            public void warn(Object msg, Throwable t) {
208                    try {
209                            _log.warn(msg, t);
210                    }
211                    catch (Exception e) {
212                            printMsg(msg);
213                    }
214            }
215    
216            protected void printMsg(Object msg) {
217                    System.err.println(msg);
218            }
219    
220            private Log _log;
221    
222    }