001/*
002 * Copyright (C) 2019 Michael N. Lipp (http://www.mnl.de)
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 */
016
017package de.mnl.osgi.lf4osgi;
018
019import de.mnl.osgi.lf4osgi.core.AbstractLoggerFacade;
020import de.mnl.osgi.lf4osgi.core.LoggerGroup;
021
022import java.util.function.Supplier;
023
024import org.osgi.service.log.LoggerConsumer;
025import org.osgi.service.log.LoggerFactory;
026
027/**
028 * The implementation of the facade for OSGi loggers. This type should
029 * not be used by consumers of this API. Rather, declare your loggers
030 * to be of type (OSGi) {@link org.osgi.service.log.Logger}, if you want
031 * the OSGi API only, or of type {@link Logger} (from this package) if 
032 * you want to use the message supplying closures. 
033 */
034@SuppressWarnings({ "PMD.TooManyMethods", "PMD.ExcessivePublicCount" })
035public class Lf4OsgiLogger extends AbstractLoggerFacade<Lf4OsgiLogger>
036        implements Logger {
037
038    @SuppressWarnings("PMD.LoggerIsNotStaticFinal")
039    private org.osgi.service.log.Logger delegee;
040
041    /**
042     * Instantiates a new logger for the given bundle with the
043     * provided name.
044     *
045     * @param context the context
046     * @param name the name
047     */
048    public Lf4OsgiLogger(LoggerGroup context, String name) {
049        super(context, name);
050    }
051
052    @Override
053    public void loggerFactoryUpdated(LoggerFactory factory) {
054        delegee = factory.getLogger(getBundle(), getName(), Logger.class);
055    }
056
057    @Override
058    public boolean isTraceEnabled() {
059        return delegee.isTraceEnabled();
060    }
061
062    @Override
063    public void trace(String message) {
064        delegee.trace(message);
065    }
066
067    @Override
068    public void trace(String format, Object arg) {
069        delegee.trace(format, arg);
070    }
071
072    @Override
073    public void trace(String format, Object arg1, Object arg2) {
074        delegee.trace(format, arg1, arg2);
075    }
076
077    @Override
078    public void trace(String format, Object... arguments) {
079        delegee.trace(format, arguments);
080    }
081
082    @Override
083    public <E extends Exception> void trace(LoggerConsumer<E> consumer)
084            throws E {
085        delegee.trace(consumer);
086    }
087
088    @Override
089    public void trace(Supplier<String> messageSupplier) {
090        if (delegee.isTraceEnabled()) {
091            delegee.trace(messageSupplier.get());
092        }
093    }
094
095    @Override
096    public void trace(Supplier<String> messageSupplier, Throwable thr) {
097        if (delegee.isTraceEnabled()) {
098            delegee.trace(messageSupplier.get(), thr);
099        }
100    }
101
102    @Override
103    public boolean isDebugEnabled() {
104        return delegee.isDebugEnabled();
105    }
106
107    @Override
108    public void debug(String message) {
109        delegee.debug(message);
110    }
111
112    @Override
113    public void debug(String format, Object arg) {
114        delegee.debug(format, arg);
115    }
116
117    @Override
118    public void debug(String format, Object arg1, Object arg2) {
119        delegee.debug(format, arg1, arg2);
120    }
121
122    @Override
123    public void debug(String format, Object... arguments) {
124        delegee.debug(format, arguments);
125    }
126
127    @Override
128    public <E extends Exception> void debug(LoggerConsumer<E> consumer)
129            throws E {
130        delegee.debug(consumer);
131    }
132
133    @Override
134    public void debug(Supplier<String> messageSupplier) {
135        if (delegee.isDebugEnabled()) {
136            delegee.debug(messageSupplier.get());
137        }
138    }
139
140    @Override
141    public void debug(Supplier<String> messageSupplier, Throwable thr) {
142        if (delegee.isDebugEnabled()) {
143            delegee.debug(messageSupplier.get(), thr);
144        }
145    }
146
147    @Override
148    public boolean isInfoEnabled() {
149        return delegee.isInfoEnabled();
150    }
151
152    @Override
153    public void info(String message) {
154        delegee.info(message);
155    }
156
157    @Override
158    public void info(String format, Object arg) {
159        delegee.info(format, arg);
160    }
161
162    @Override
163    public void info(String format, Object arg1, Object arg2) {
164        delegee.info(format, arg1, arg2);
165    }
166
167    @Override
168    public void info(String format, Object... arguments) {
169        delegee.info(format, arguments);
170    }
171
172    @Override
173    public <E extends Exception> void info(LoggerConsumer<E> consumer)
174            throws E {
175        delegee.info(consumer);
176    }
177
178    @Override
179    public void info(Supplier<String> messageSupplier) {
180        if (delegee.isInfoEnabled()) {
181            delegee.info(messageSupplier.get());
182        }
183    }
184
185    @Override
186    public void info(Supplier<String> messageSupplier, Throwable thr) {
187        if (delegee.isInfoEnabled()) {
188            delegee.info(messageSupplier.get(), thr);
189        }
190    }
191
192    @Override
193    public boolean isWarnEnabled() {
194        return delegee.isWarnEnabled();
195    }
196
197    @Override
198    public void warn(String message) {
199        delegee.warn(message);
200    }
201
202    @Override
203    public void warn(String format, Object arg) {
204        delegee.warn(format, arg);
205    }
206
207    @Override
208    public void warn(String format, Object arg1, Object arg2) {
209        delegee.warn(format, arg1, arg2);
210    }
211
212    @Override
213    public void warn(String format, Object... arguments) {
214        delegee.warn(format, arguments);
215    }
216
217    @Override
218    public void warn(Supplier<String> messageSupplier) {
219        if (delegee.isWarnEnabled()) {
220            delegee.warn(messageSupplier.get());
221        }
222    }
223
224    @Override
225    public <E extends Exception> void warn(LoggerConsumer<E> consumer)
226            throws E {
227        delegee.warn(consumer);
228    }
229
230    @Override
231    public void warn(Supplier<String> messageSupplier, Throwable thr) {
232        if (delegee.isWarnEnabled()) {
233            delegee.warn(messageSupplier.get(), thr);
234        }
235    }
236
237    @Override
238    public boolean isErrorEnabled() {
239        return delegee.isErrorEnabled();
240    }
241
242    @Override
243    public void error(String message) {
244        delegee.error(message);
245    }
246
247    @Override
248    public void error(String format, Object arg) {
249        delegee.error(format, arg);
250    }
251
252    @Override
253    public void error(String format, Object arg1, Object arg2) {
254        delegee.error(format, arg1, arg2);
255    }
256
257    @Override
258    public void error(String format, Object... arguments) {
259        delegee.error(format, arguments);
260    }
261
262    @Override
263    public <E extends Exception> void error(LoggerConsumer<E> consumer)
264            throws E {
265        delegee.error(consumer);
266    }
267
268    @Override
269    public void error(Supplier<String> messageSupplier) {
270        if (delegee.isErrorEnabled()) {
271            delegee.error(messageSupplier.get());
272        }
273    }
274
275    @Override
276    public void error(Supplier<String> messageSupplier, Throwable thr) {
277        if (delegee.isErrorEnabled()) {
278            delegee.error(messageSupplier.get(), thr);
279        }
280    }
281
282    @Override
283    public void audit(String message) {
284        delegee.audit(message);
285    }
286
287    @Override
288    public void audit(String format, Object arg) {
289        delegee.audit(format, arg);
290    }
291
292    @Override
293    public void audit(String format, Object arg1, Object arg2) {
294        delegee.audit(format, arg1, arg2);
295    }
296
297    @Override
298    public void audit(String format, Object... arguments) {
299        delegee.audit(format, arguments);
300    }
301
302}