001/*
002 *  Copyright 2015 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.core.util;
017
018import org.apache.avalon.framework.logger.Logger;
019import org.slf4j.Marker;
020import org.slf4j.helpers.FormattingTuple;
021import org.slf4j.helpers.MessageFormatter;
022
023/**
024 * SLF4J Logger wrapping an Avalon {@link Logger}.
025 */
026public class AvalonLoggerAdapter implements org.slf4j.Logger
027{
028    private org.apache.avalon.framework.logger.Logger _logger;
029    
030    /**
031     * Constructor
032     * @param logger the Avalon {@link Logger}.
033     */
034    public AvalonLoggerAdapter(org.apache.avalon.framework.logger.Logger logger)
035    {
036        _logger = logger;
037    }
038    
039    public String getName()
040    {
041        return null;
042    }
043
044    public boolean isTraceEnabled()
045    {
046        return _logger.isDebugEnabled();
047    }
048
049    public void trace(String msg)
050    {
051        _logger.debug(msg);
052    }
053
054    public void trace(String format, Object arg)
055    {
056        if (_logger.isDebugEnabled()) 
057        {
058            FormattingTuple ft = MessageFormatter.format(format, arg);
059            _logger.debug(ft.getMessage(), ft.getThrowable());
060        }
061    }
062
063    public void trace(String format, Object arg1, Object arg2)
064    {
065        if (_logger.isDebugEnabled()) 
066        {
067            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
068            _logger.debug(ft.getMessage(), ft.getThrowable());
069        }
070    }
071
072    public void trace(String format, Object... arguments)
073    {
074        if (_logger.isDebugEnabled()) 
075        {
076            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
077            _logger.debug(ft.getMessage(), ft.getThrowable());
078        }
079    }
080
081    public void trace(String msg, Throwable t)
082    {
083        _logger.debug(msg, t);
084    }
085
086    public boolean isTraceEnabled(Marker marker) 
087    {
088        return isTraceEnabled();
089    }
090
091    public void trace(Marker marker, String msg) 
092    {
093        trace(msg);
094    }
095
096    public void trace(Marker marker, String format, Object arg) 
097    {
098        trace(format, arg);
099    }
100
101    public void trace(Marker marker, String format, Object arg1, Object arg2) 
102    {
103        trace(format, arg1, arg2);
104    }
105
106    public void trace(Marker marker, String format, Object... arguments) 
107    {
108        trace(format, arguments);
109    }
110
111    public void trace(Marker marker, String msg, Throwable t) 
112    {
113        trace(msg, t);
114    }
115
116    public boolean isDebugEnabled()
117    {
118        return _logger.isDebugEnabled();
119    }
120
121    public void debug(String msg)
122    {
123        _logger.debug(msg);
124    }
125
126    public void debug(String format, Object arg)
127    {
128        if (_logger.isDebugEnabled()) 
129        {
130            FormattingTuple ft = MessageFormatter.format(format, arg);
131            _logger.debug(ft.getMessage(), ft.getThrowable());
132        }
133    }
134
135    public void debug(String format, Object arg1, Object arg2)
136    {
137        if (_logger.isDebugEnabled()) 
138        {
139            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
140            _logger.debug(ft.getMessage(), ft.getThrowable());
141        }
142    }
143
144    public void debug(String format, Object... arguments)
145    {
146        if (_logger.isDebugEnabled()) 
147        {
148            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
149            _logger.debug(ft.getMessage(), ft.getThrowable());
150        }
151    }
152
153    public void debug(String msg, Throwable t)
154    {
155        _logger.debug(msg, t);
156    }
157
158    public boolean isInfoEnabled()
159    {
160        return _logger.isInfoEnabled();
161    }
162
163    public void info(String msg)
164    {
165        _logger.info(msg);
166    }
167
168    public boolean isDebugEnabled(Marker marker) 
169    {
170        return isDebugEnabled();
171    }
172
173    public void debug(Marker marker, String msg) 
174    {
175        debug(msg);
176    }
177
178    public void debug(Marker marker, String format, Object arg) 
179    {
180        debug(format, arg);
181    }
182
183    public void debug(Marker marker, String format, Object arg1, Object arg2) 
184    {
185        debug(format, arg1, arg2);
186    }
187
188    public void debug(Marker marker, String format, Object... arguments) 
189    {
190        debug(format, arguments);
191    }
192
193    public void debug(Marker marker, String msg, Throwable t) 
194    {
195        debug(msg, t);
196    }
197
198    public void info(String format, Object arg)
199    {
200        if (_logger.isInfoEnabled()) 
201        {
202            FormattingTuple ft = MessageFormatter.format(format, arg);
203            _logger.info(ft.getMessage(), ft.getThrowable());
204        }
205    }
206
207    public void info(String format, Object arg1, Object arg2)
208    {
209        if (_logger.isInfoEnabled()) 
210        {
211            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
212            _logger.info(ft.getMessage(), ft.getThrowable());
213        }
214    }
215
216    public void info(String format, Object... arguments)
217    {
218        if (_logger.isInfoEnabled()) 
219        {
220            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
221            _logger.info(ft.getMessage(), ft.getThrowable());
222        }
223    }
224
225    public void info(String msg, Throwable t)
226    {
227        _logger.info(msg, t);
228    }
229
230    public boolean isInfoEnabled(Marker marker) 
231    {
232        return isInfoEnabled();
233    }
234
235    public void info(Marker marker, String msg) 
236    {
237        info(msg);
238    }
239
240    public void info(Marker marker, String format, Object arg) 
241    {
242        info(format, arg);
243    }
244
245    public void info(Marker marker, String format, Object arg1, Object arg2) 
246    {
247        info(format, arg1, arg2);
248    }
249
250    public void info(Marker marker, String format, Object... arguments) 
251    {
252        info(format, arguments);
253    }
254
255    public void info(Marker marker, String msg, Throwable t) 
256    {
257        info(msg, t);
258    }
259
260    public boolean isWarnEnabled()
261    {
262        return _logger.isWarnEnabled();
263    }
264
265    public void warn(String msg)
266    {
267        _logger.warn(msg);
268    }
269
270    public void warn(String format, Object arg)
271    {
272        if (_logger.isWarnEnabled()) 
273        {
274            FormattingTuple ft = MessageFormatter.format(format, arg);
275            _logger.warn(ft.getMessage(), ft.getThrowable());
276        }
277    }
278
279    public void warn(String format, Object... arguments)
280    {
281        if (_logger.isWarnEnabled()) 
282        {
283            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
284            _logger.warn(ft.getMessage(), ft.getThrowable());
285        }
286    }
287
288    public void warn(String format, Object arg1, Object arg2)
289    {
290        if (_logger.isWarnEnabled()) 
291        {
292            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
293            _logger.warn(ft.getMessage(), ft.getThrowable());
294        }
295    }
296
297    public void warn(String msg, Throwable t)
298    {
299        _logger.warn(msg, t);
300    }
301
302    public boolean isWarnEnabled(Marker marker) 
303    {
304        return isWarnEnabled();
305    }
306
307    public void warn(Marker marker, String msg) 
308    {
309        warn(msg);
310    }
311
312    public void warn(Marker marker, String format, Object arg) 
313    {
314        warn(format, arg);
315    }
316
317    public void warn(Marker marker, String format, Object arg1, Object arg2) 
318    {
319        warn(format, arg1, arg2);
320    }
321
322    public void warn(Marker marker, String format, Object... arguments) 
323    {
324        warn(format, arguments);
325    }
326
327    public void warn(Marker marker, String msg, Throwable t) 
328    {
329        warn(msg, t);
330    }
331
332    public boolean isErrorEnabled()
333    {
334        return _logger.isErrorEnabled();
335    }
336
337    public void error(String msg)
338    {
339        _logger.error(msg);
340    }
341
342    public void error(String format, Object arg)
343    {
344        if (_logger.isErrorEnabled()) 
345        {
346            FormattingTuple ft = MessageFormatter.format(format, arg);
347            _logger.error(ft.getMessage(), ft.getThrowable());
348        }
349    }
350
351    public void error(String format, Object arg1, Object arg2)
352    {
353        if (_logger.isErrorEnabled()) 
354        {
355            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
356            _logger.error(ft.getMessage(), ft.getThrowable());
357        }
358    }
359
360    public void error(String format, Object... arguments)
361    {
362        if (_logger.isErrorEnabled()) 
363        {
364            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
365            _logger.error(ft.getMessage(), ft.getThrowable());
366        }
367    }
368
369    public void error(String msg, Throwable t)
370    {
371        _logger.error(msg, t);
372    }
373    
374    public boolean isErrorEnabled(Marker marker) 
375    {
376        return isErrorEnabled();
377    }
378
379    public void error(Marker marker, String msg) 
380    {
381        error(msg);
382    }
383
384    public void error(Marker marker, String format, Object arg) 
385    {
386        error(format, arg);
387    }
388
389    public void error(Marker marker, String format, Object arg1, Object arg2) 
390    {
391        error(format, arg1, arg2);
392    }
393
394    public void error(Marker marker, String format, Object... arguments) 
395    {
396        error(format, arguments);
397    }
398
399    public void error(Marker marker, String msg, Throwable t) 
400    {
401        error(msg, t);
402    }
403}