Added overloads for directly passing message
This commit is contained in:
parent
4ef5243bbe
commit
da36fafde0
|
@ -19,16 +19,32 @@ interface Logger {
|
|||
val isTraceEnabled: Boolean
|
||||
|
||||
|
||||
fun fatal(message: String, exception: Throwable? = null, vararg arguments: Any)
|
||||
|
||||
fun fatal(exception: Throwable? = null, vararg arguments: Any, message: () -> String)
|
||||
|
||||
|
||||
fun error(message: String, exception: Throwable? = null, vararg arguments: Any)
|
||||
|
||||
fun error(exception: Throwable? = null, vararg arguments: Any, message: () -> String)
|
||||
|
||||
|
||||
fun warn(message: String, exception: Throwable? = null, vararg arguments: Any)
|
||||
|
||||
fun warn(exception: Throwable? = null, vararg arguments: Any, message: () -> String)
|
||||
|
||||
fun info(message: String, exception: Throwable? = null, vararg arguments: Any)
|
||||
|
||||
fun info(exception: Throwable? = null, vararg arguments: Any, message: () -> String)
|
||||
|
||||
|
||||
fun debug(message: String, exception: Throwable? = null, vararg arguments: Any)
|
||||
|
||||
fun debug(exception: Throwable? = null, vararg arguments: Any, message: () -> String)
|
||||
|
||||
|
||||
fun trace(message: String, exception: Throwable? = null, vararg arguments: Any)
|
||||
|
||||
fun trace(exception: Throwable? = null, vararg arguments: Any, message: () -> String)
|
||||
|
||||
}
|
|
@ -24,30 +24,60 @@ abstract class LoggerBase(
|
|||
open fun isEnabled(level: LogLevel) = level.priority <= this.level.priority
|
||||
|
||||
|
||||
override fun fatal(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
logIfEnabled(LogLevel.Fatal, exception, { message }, *arguments)
|
||||
}
|
||||
|
||||
override fun fatal(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
logIfEnabled(LogLevel.Fatal, exception, message, *arguments)
|
||||
}
|
||||
|
||||
|
||||
override fun error(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
logIfEnabled(LogLevel.Error, exception, { message }, *arguments)
|
||||
}
|
||||
|
||||
override fun error(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
logIfEnabled(LogLevel.Error, exception, message, *arguments)
|
||||
}
|
||||
|
||||
|
||||
override fun warn(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
logIfEnabled(LogLevel.Warn, exception, { message }, *arguments)
|
||||
}
|
||||
|
||||
override fun warn(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
logIfEnabled(LogLevel.Warn, exception, message, *arguments)
|
||||
}
|
||||
|
||||
|
||||
override fun info(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
logIfEnabled(LogLevel.Info, exception, { message }, *arguments)
|
||||
}
|
||||
|
||||
override fun info(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
logIfEnabled(LogLevel.Info, exception, message, *arguments)
|
||||
}
|
||||
|
||||
|
||||
override fun debug(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
logIfEnabled(LogLevel.Debug, exception, { message }, *arguments)
|
||||
}
|
||||
|
||||
override fun debug(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
logIfEnabled(LogLevel.Debug, exception, message, *arguments)
|
||||
}
|
||||
|
||||
|
||||
override fun trace(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
logIfEnabled(LogLevel.Trace, exception, { message }, *arguments)
|
||||
}
|
||||
|
||||
override fun trace(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
logIfEnabled(LogLevel.Trace, exception, message, *arguments)
|
||||
}
|
||||
|
||||
|
||||
open fun logIfEnabled(level: LogLevel, exception: Throwable? = null, message: () -> String, vararg arguments: Any) {
|
||||
if (isEnabled(level)) {
|
||||
log(level, createMessage(exception, message(), *arguments))
|
||||
|
|
|
@ -26,30 +26,60 @@ open class Slf4jLogger(protected val slf4jLogger: org.slf4j.Logger) : Logger {
|
|||
get() = slf4jLogger.isTraceEnabled
|
||||
|
||||
|
||||
override fun fatal(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
error(message, exception, arguments)
|
||||
}
|
||||
|
||||
override fun fatal(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
error(exception, *arguments, message = message)
|
||||
}
|
||||
|
||||
|
||||
override fun error(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
log(exception, arguments, { message }, { msg, args -> slf4jLogger.error(msg, *args) } )
|
||||
}
|
||||
|
||||
override fun error(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
log(exception, arguments, message, { msg, args -> slf4jLogger.error(msg, *args) } )
|
||||
}
|
||||
|
||||
|
||||
override fun warn(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
log(exception, arguments, { message }, { msg, args -> slf4jLogger.warn(msg, *args) } )
|
||||
}
|
||||
|
||||
override fun warn(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
log(exception, arguments, message, { msg, args -> slf4jLogger.warn(msg, *args) } )
|
||||
}
|
||||
|
||||
|
||||
override fun info(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
log(exception, arguments, { message }, { msg, args -> slf4jLogger.info(msg, *args) } )
|
||||
}
|
||||
|
||||
override fun info(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
log(exception, arguments, message, { msg, args -> slf4jLogger.info(msg, *args) } )
|
||||
}
|
||||
|
||||
|
||||
override fun debug(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
log(exception, arguments, { message }, { msg, args -> slf4jLogger.debug(msg, *args) } )
|
||||
}
|
||||
|
||||
override fun debug(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
log(exception, arguments, message, { msg, args -> slf4jLogger.debug(msg, *args) } )
|
||||
}
|
||||
|
||||
|
||||
override fun trace(message: String, exception: Throwable?, vararg arguments: Any) {
|
||||
log(exception, arguments, { message }, { msg, args -> slf4jLogger.trace(msg, *args) } )
|
||||
}
|
||||
|
||||
override fun trace(exception: Throwable?, vararg arguments: Any, message: () -> String) {
|
||||
log(exception, arguments, message, { msg, args -> slf4jLogger.trace(msg, *args) } )
|
||||
}
|
||||
|
||||
|
||||
protected open fun log(exception: Throwable?, arguments: Array<out Any>, messageCreator: () -> String,
|
||||
logOnLevel: (String, Array<out Any>) -> Unit) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue