Class LoggerAtLevel
- java.lang.Object
-
- org.fissore.slf4j.LoggerAtLevel
-
- Direct Known Subclasses:
NOOPLogger
public class LoggerAtLevel extends Object
This is where the fluent API of slf4j-fluent is implemented. With its methods we can build the log message, assign an exception to it, and specify logging limits such as quantity ("don't log this more than once every 5 times") or time ("don't log this more than once every 2 seconds").In order to avoid implicit array creation when using varargs, this class provides a number overloaded version of the
logmethod with increasing number of arguments.logmethods arguments can be of any type. If they areSuppliers, they will be called only when actually logging, thus providing lazy argument evaluation. Also seeUtil.lazy(Supplier).When filtering log entries based on quantity or time, we need to generate the "call site" which is the fully qualified name of the class, plus the name of the method calling the
logmethod, plus the line number.- See Also:
Util.lazy(Supplier)
-
-
Constructor Summary
Constructors Constructor Description LoggerAtLevel(BiConsumer<String,Object[]> loggerMethod, org.fissore.slf4j.TriConsumer<org.slf4j.Marker,String,Object[]> loggerMethodWithMarker, boolean isLocationAwareLogger, org.slf4j.Logger logger, int level)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LoggerAtLevelevery(int amountOfCalls)Configures thisLoggerAtLevelto log at most every number of timesLoggerAtLevelevery(long amountOfTime, ChronoUnit unit)Configures thisLoggerAtLevelto log at most every amount of time.voidlog(String message)Logs a message with no paramsvoidlog(String format, Object arg)Logs a message with one paramvoidlog(String format, Object... args)Logs a message with varying number of paramsvoidlog(String format, Object arg1, Object arg2)Logs a message with two paramsvoidlog(String format, Object arg1, Object arg2, Object arg3)Logs a message with three paramsvoidlog(String format, Object arg1, Object arg2, Object arg3, Object arg4)Logs a message with four paramsvoidlog(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)Logs a message with five paramsvoidlog(Supplier<String> messageSupplier)Logs a message with no paramsvoidlog(Supplier<String> formatSupplier, Object arg)Logs a message with one paramvoidlog(Supplier<String> formatSupplier, Object... args)Logs a message with varying number of paramsvoidlog(Supplier<String> formatSupplier, Object arg1, Object arg2)Logs a message with two paramsvoidlog(Supplier<String> formatSupplier, Object arg1, Object arg2, Object arg3)Logs a message with three paramsvoidlog(Supplier<String> formatSupplier, Object arg1, Object arg2, Object arg3, Object arg4)Logs a message with four paramsvoidlog(Supplier<String> formatSupplier, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)Logs a message with five paramsLoggerAtLevelwithCause(Throwable cause)Associates an exception to this log entry.LoggerAtLevelwithMarker(org.slf4j.Marker marker)
-
-
-
Constructor Detail
-
LoggerAtLevel
public LoggerAtLevel(BiConsumer<String,Object[]> loggerMethod, org.fissore.slf4j.TriConsumer<org.slf4j.Marker,String,Object[]> loggerMethodWithMarker, boolean isLocationAwareLogger, org.slf4j.Logger logger, int level)
-
-
Method Detail
-
withCause
public LoggerAtLevel withCause(Throwable cause)
Associates an exception to this log entry.- Parameters:
cause- the exception we want to associate this log entry to- Returns:
- this instance of
LoggerAtLevel
-
withMarker
public LoggerAtLevel withMarker(org.slf4j.Marker marker)
-
every
public LoggerAtLevel every(long amountOfTime, ChronoUnit unit)
Configures thisLoggerAtLevelto log at most every amount of time.For example, say we want to log at most every 2 seconds. If our code attempts to log multiple times for 5 seconds, we'll see only 3 log entries in our log files: the first one, the first one after 2 seconds, and the first one after 4 seconds.
- Parameters:
amountOfTime- the amount of time to wait between log entriesunit- the unit of time expressed by amountOfTime- Returns:
- this instance of
LoggerAtLevel - Throws:
IllegalStateException- if thisLoggerAtLevelwas already configured to limit logging by quantity
-
every
public LoggerAtLevel every(int amountOfCalls)
Configures thisLoggerAtLevelto log at most every number of timesFor example, say we want to log at most every 5 times. If our code attempts to log 8 times, we'll see 2 log entries in our log files: the first one, and the fifth one.
- Parameters:
amountOfCalls- the amount of calls that must be made before logging- Returns:
- this instance of
LoggerAtLevel - Throws:
IllegalStateException- if thisLoggerAtLevelwas already configured to limit logging by time
-
log
public void log(String message)
Logs a message with no params- Parameters:
message- the log message
-
log
public void log(Supplier<String> messageSupplier)
Logs a message with no params- Parameters:
messageSupplier- the log message supplier
-
log
public void log(String format, Object arg)
Logs a message with one param- Parameters:
format- the log messagearg- a log message param
-
log
public void log(Supplier<String> formatSupplier, Object arg)
Logs a message with one param- Parameters:
formatSupplier- the log message supplierarg- a log message param
-
log
public void log(String format, Object arg1, Object arg2)
Logs a message with two params- Parameters:
format- the log messagearg1- a log message paramarg2- a log message param
-
log
public void log(Supplier<String> formatSupplier, Object arg1, Object arg2)
Logs a message with two params- Parameters:
formatSupplier- the log message supplierarg1- a log message paramarg2- a log message param
-
log
public void log(String format, Object arg1, Object arg2, Object arg3)
Logs a message with three params- Parameters:
format- the log messagearg1- a log message paramarg2- a log message paramarg3- a log message param
-
log
public void log(Supplier<String> formatSupplier, Object arg1, Object arg2, Object arg3)
Logs a message with three params- Parameters:
formatSupplier- the log message supplierarg1- a log message paramarg2- a log message paramarg3- a log message param
-
log
public void log(String format, Object arg1, Object arg2, Object arg3, Object arg4)
Logs a message with four params- Parameters:
format- the log messagearg1- a log message paramarg2- a log message paramarg3- a log message paramarg4- a log message param
-
log
public void log(Supplier<String> formatSupplier, Object arg1, Object arg2, Object arg3, Object arg4)
Logs a message with four params- Parameters:
formatSupplier- the log message supplierarg1- a log message paramarg2- a log message paramarg3- a log message paramarg4- a log message param
-
log
public void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
Logs a message with five params- Parameters:
format- the log messagearg1- a log message paramarg2- a log message paramarg3- a log message paramarg4- a log message paramarg5- a log message param
-
log
public void log(Supplier<String> formatSupplier, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
Logs a message with five params- Parameters:
formatSupplier- the log message supplierarg1- a log message paramarg2- a log message paramarg3- a log message paramarg4- a log message paramarg5- a log message param
-
log
public void log(String format, Object... args)
Logs a message with varying number of params- Parameters:
format- the log messageargs- log message params
-
-