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.helpers.FormattingTuple;
020import org.slf4j.helpers.MarkerIgnoringBase;
021import org.slf4j.helpers.MessageFormatter;
022
023/**
024 * SLF4J Logger wrapping an Avalon {@link Logger}.
025 */
026public class AvalonLoggerAdapter extends MarkerIgnoringBase
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 boolean isTraceEnabled()
040    {
041        return _logger.isDebugEnabled();
042    }
043
044    public void trace(String msg)
045    {
046        _logger.debug(msg);
047    }
048
049    public void trace(String format, Object arg)
050    {
051        if (_logger.isDebugEnabled()) 
052        {
053            FormattingTuple ft = MessageFormatter.format(format, arg);
054            _logger.debug(ft.getMessage(), ft.getThrowable());
055        }
056    }
057
058    public void trace(String format, Object arg1, Object arg2)
059    {
060        if (_logger.isDebugEnabled()) 
061        {
062            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
063            _logger.debug(ft.getMessage(), ft.getThrowable());
064        }
065    }
066
067    public void trace(String format, Object... arguments)
068    {
069        if (_logger.isDebugEnabled()) 
070        {
071            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
072            _logger.debug(ft.getMessage(), ft.getThrowable());
073        }
074    }
075
076    public void trace(String msg, Throwable t)
077    {
078        _logger.debug(msg, t);
079    }
080
081    public boolean isDebugEnabled()
082    {
083        return _logger.isDebugEnabled();
084    }
085
086    public void debug(String msg)
087    {
088        _logger.debug(msg);
089    }
090
091    public void debug(String format, Object arg)
092    {
093        if (_logger.isDebugEnabled()) 
094        {
095            FormattingTuple ft = MessageFormatter.format(format, arg);
096            _logger.debug(ft.getMessage(), ft.getThrowable());
097        }
098    }
099
100    public void debug(String format, Object arg1, Object arg2)
101    {
102        if (_logger.isDebugEnabled()) 
103        {
104            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
105            _logger.debug(ft.getMessage(), ft.getThrowable());
106        }
107    }
108
109    public void debug(String format, Object... arguments)
110    {
111        if (_logger.isDebugEnabled()) 
112        {
113            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
114            _logger.debug(ft.getMessage(), ft.getThrowable());
115        }
116    }
117
118    public void debug(String msg, Throwable t)
119    {
120        _logger.debug(msg, t);
121    }
122
123    public boolean isInfoEnabled()
124    {
125        return _logger.isInfoEnabled();
126    }
127
128    public void info(String msg)
129    {
130        _logger.info(msg);
131    }
132
133    public void info(String format, Object arg)
134    {
135        if (_logger.isInfoEnabled()) 
136        {
137            FormattingTuple ft = MessageFormatter.format(format, arg);
138            _logger.info(ft.getMessage(), ft.getThrowable());
139        }
140    }
141
142    public void info(String format, Object arg1, Object arg2)
143    {
144        if (_logger.isInfoEnabled()) 
145        {
146            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
147            _logger.info(ft.getMessage(), ft.getThrowable());
148        }
149    }
150
151    public void info(String format, Object... arguments)
152    {
153        if (_logger.isInfoEnabled()) 
154        {
155            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
156            _logger.info(ft.getMessage(), ft.getThrowable());
157        }
158    }
159
160    public void info(String msg, Throwable t)
161    {
162        _logger.info(msg, t);
163    }
164
165    public boolean isWarnEnabled()
166    {
167        return _logger.isWarnEnabled();
168    }
169
170    public void warn(String msg)
171    {
172        _logger.warn(msg);
173    }
174
175    public void warn(String format, Object arg)
176    {
177        if (_logger.isWarnEnabled()) 
178        {
179            FormattingTuple ft = MessageFormatter.format(format, arg);
180            _logger.warn(ft.getMessage(), ft.getThrowable());
181        }
182    }
183
184    public void warn(String format, Object... arguments)
185    {
186        if (_logger.isWarnEnabled()) 
187        {
188            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
189            _logger.warn(ft.getMessage(), ft.getThrowable());
190        }
191    }
192
193    public void warn(String format, Object arg1, Object arg2)
194    {
195        if (_logger.isWarnEnabled()) 
196        {
197            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
198            _logger.warn(ft.getMessage(), ft.getThrowable());
199        }
200    }
201
202    public void warn(String msg, Throwable t)
203    {
204        _logger.warn(msg, t);
205    }
206
207    public boolean isErrorEnabled()
208    {
209        return _logger.isErrorEnabled();
210    }
211
212    public void error(String msg)
213    {
214        _logger.error(msg);
215    }
216
217    public void error(String format, Object arg)
218    {
219        if (_logger.isErrorEnabled()) 
220        {
221            FormattingTuple ft = MessageFormatter.format(format, arg);
222            _logger.error(ft.getMessage(), ft.getThrowable());
223        }
224    }
225
226    public void error(String format, Object arg1, Object arg2)
227    {
228        if (_logger.isErrorEnabled()) 
229        {
230            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
231            _logger.error(ft.getMessage(), ft.getThrowable());
232        }
233    }
234
235    public void error(String format, Object... arguments)
236    {
237        if (_logger.isErrorEnabled()) 
238        {
239            FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
240            _logger.error(ft.getMessage(), ft.getThrowable());
241        }
242    }
243
244    public void error(String msg, Throwable t)
245    {
246        _logger.error(msg, t);
247    }
248}