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