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 java.util.function.Supplier; 020 021/** 022 * An extended OSGi {@link org.osgi.service.log.Logger} interface. 023 * It provides the additional methods that accept a {@link Supplier} 024 * for the message as a parameter. This allows you to write 025 * statements such as: 026 * <pre> 027 * logger.warn(() -> String.format("Value is %d.", 42)); 028 * </pre> 029 */ 030public interface Logger extends org.osgi.service.log.Logger { 031 032 /** 033 * If trace level is enabled, get the message from the supplier 034 * and log it. 035 * 036 * @param messageSupplier the message supplier 037 */ 038 void trace(Supplier<String> messageSupplier); 039 040 /** 041 * If trace level is enabled, get the message from the supplier 042 * and log it together withe the provided throwable. 043 * 044 * @param messageSupplier the message supplier 045 * @param thr the Throwable 046 */ 047 void trace(Supplier<String> messageSupplier, Throwable thr); 048 049 /** 050 * If debug level is enabled, get the message from the supplier 051 * and log it. 052 * 053 * @param messageSupplier the message supplier 054 */ 055 void debug(Supplier<String> messageSupplier); 056 057 /** 058 * If debug level is enabled, get the message from the supplier 059 * and log it together withe the provided throwable. 060 * 061 * @param messageSupplier the message supplier 062 * @param thr the Throwable 063 */ 064 void debug(Supplier<String> messageSupplier, Throwable thr); 065 066 /** 067 * If info level is enabled, get the message from the supplier 068 * and log it. 069 * 070 * @param messageSupplier the message supplier 071 */ 072 void info(Supplier<String> messageSupplier); 073 074 /** 075 * If info level is enabled, get the message from the supplier 076 * and log it together withe the provided throwable. 077 * 078 * @param messageSupplier the message supplier 079 * @param thr the Throwable 080 */ 081 void info(Supplier<String> messageSupplier, Throwable thr); 082 083 /** 084 * If warn level is enabled, get the message from the supplier 085 * and log it. 086 * 087 * @param messageSupplier the message supplier 088 */ 089 void warn(Supplier<String> messageSupplier); 090 091 /** 092 * If warn level is enabled, get the message from the supplier 093 * and log it together withe the provided throwable. 094 * 095 * @param messageSupplier the message supplier 096 * @param thr the Throwable 097 */ 098 void warn(Supplier<String> messageSupplier, Throwable thr); 099 100 /** 101 * If error level is enabled, get the message from the supplier 102 * and log it. 103 * 104 * @param messageSupplier the message supplier 105 */ 106 void error(Supplier<String> messageSupplier); 107 108 /** 109 * If error level is enabled, get the message from the supplier 110 * and log it together withe the provided throwable. 111 * 112 * @param messageSupplier the message supplier 113 * @param thr the Throwable 114 */ 115 void error(Supplier<String> messageSupplier, Throwable thr); 116 117}