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