Skip to content

Commit

Permalink
Add throwable handling to logging methods
Browse files Browse the repository at this point in the history
Extended the logger methods to include throwable handling across various logging levels. This allows for better error reporting and stack trace logging, improving debugging capabilities. Updated the project version to 0.12.0 to reflect these enhancements.
  • Loading branch information
smyrgeorge committed Oct 23, 2024
1 parent 82fab75 commit 8d459a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "io.github.smyrgeorge"
version = "0.11.0"
version = "0.12.0"

plugins {
alias(libs.plugins.dokka)
Expand Down
24 changes: 24 additions & 0 deletions log4k/src/commonMain/kotlin/io/github/smyrgeorge/log4k/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,55 @@ abstract class Logger(
}

inline fun trace(f: () -> String): Unit = if (Level.TRACE.shouldLog()) trace(f()) else Unit
inline fun trace(t: Throwable, f: () -> String): Unit = if (Level.TRACE.shouldLog()) trace(f(), t) else Unit
inline fun debug(f: () -> String): Unit = if (Level.DEBUG.shouldLog()) debug(f()) else Unit
inline fun debug(t: Throwable, f: () -> String): Unit = if (Level.DEBUG.shouldLog()) debug(f(), t) else Unit
inline fun info(f: () -> String): Unit = if (Level.INFO.shouldLog()) info(f()) else Unit
inline fun info(t: Throwable, f: () -> String): Unit = if (Level.INFO.shouldLog()) info(f(), t) else Unit
inline fun warn(f: () -> String): Unit = if (Level.WARN.shouldLog()) warn(f()) else Unit
inline fun warn(t: Throwable, f: () -> String): Unit = if (Level.WARN.shouldLog()) warn(f(), t) else Unit
inline fun error(f: () -> String?): Unit = if (Level.ERROR.shouldLog()) error(f()) else Unit
inline fun error(t: Throwable, f: () -> String?): Unit = if (Level.ERROR.shouldLog()) error(f(), t) else Unit

inline fun trace(span: Span, f: () -> String): Unit = if (Level.TRACE.shouldLog()) trace(span, f()) else Unit
inline fun trace(span: Span, t: Throwable, f: () -> String): Unit =
if (Level.TRACE.shouldLog()) trace(span, f(), t) else Unit

inline fun debug(span: Span, f: () -> String): Unit = if (Level.DEBUG.shouldLog()) debug(span, f()) else Unit
inline fun debug(span: Span, t: Throwable, f: () -> String): Unit =
if (Level.DEBUG.shouldLog()) debug(span, f(), t) else Unit

inline fun info(span: Span, f: () -> String): Unit = if (Level.INFO.shouldLog()) info(span, f()) else Unit
inline fun info(span: Span, t: Throwable, f: () -> String): Unit =
if (Level.INFO.shouldLog()) info(span, f(), t) else Unit

inline fun warn(span: Span, f: () -> String): Unit = if (Level.WARN.shouldLog()) warn(span, f()) else Unit
inline fun warn(span: Span, t: Throwable, f: () -> String): Unit =
if (Level.WARN.shouldLog()) warn(span, f(), t) else Unit

inline fun error(span: Span, f: () -> String?): Unit = if (Level.ERROR.shouldLog()) error(span, f()) else Unit
inline fun error(span: Span, t: Throwable, f: () -> String?): Unit =
if (Level.ERROR.shouldLog()) error(span, f(), t) else Unit

fun trace(msg: String, vararg args: Any?): Unit = log(Level.TRACE, null, msg, args)
fun trace(msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.TRACE, null, msg, t, args)
fun debug(msg: String, vararg args: Any?): Unit = log(Level.DEBUG, null, msg, args)
fun debug(msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.DEBUG, null, msg, t, args)
fun info(msg: String, vararg args: Any?): Unit = log(Level.INFO, null, msg, args)
fun info(msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.INFO, null, msg, t, args)
fun warn(msg: String, vararg args: Any?): Unit = log(Level.WARN, null, msg, args)
fun warn(msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.WARN, null, msg, t, args)
fun error(msg: String?, vararg args: Any?): Unit = log(Level.ERROR, null, msg ?: "", args)
fun error(msg: String?, t: Throwable, vararg args: Any?): Unit = log(Level.ERROR, null, msg ?: "", t, args)

fun trace(span: Span, msg: String, vararg args: Any?): Unit = log(Level.TRACE, span, msg, args)
fun trace(span: Span, msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.TRACE, span, msg, t, args)
fun debug(span: Span, msg: String, vararg args: Any?): Unit = log(Level.DEBUG, span, msg, args)
fun debug(span: Span, msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.DEBUG, span, msg, t, args)
fun info(span: Span, msg: String, vararg args: Any?): Unit = log(Level.INFO, span, msg, args)
fun info(span: Span, msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.INFO, span, msg, t, args)
fun warn(span: Span, msg: String, vararg args: Any?): Unit = log(Level.WARN, span, msg, args)
fun warn(span: Span, msg: String, t: Throwable, vararg args: Any?): Unit = log(Level.WARN, span, msg, t, args)
fun error(span: Span, msg: String?, vararg args: Any?): Unit = log(Level.ERROR, span, msg ?: "", args)
fun error(span: Span, msg: String?, t: Throwable, vararg args: Any?): Unit =
log(Level.ERROR, span, msg ?: "", t, args)
Expand Down

0 comments on commit 8d459a2

Please sign in to comment.