diff --git a/napier/src/commonMain/kotlin/io/github/aakira/napier/Napier.kt b/napier/src/commonMain/kotlin/io/github/aakira/napier/Napier.kt index d8ebce4..ca5022c 100644 --- a/napier/src/commonMain/kotlin/io/github/aakira/napier/Napier.kt +++ b/napier/src/commonMain/kotlin/io/github/aakira/napier/Napier.kt @@ -61,7 +61,7 @@ object Napier { * @param tag String: Used to identify the source of a log message. It usually * identifies the class or activity where the log call occurs. This value may be null. */ - fun v(message: String, throwable: Throwable? = null, tag: String? = null) { + fun v(message: String?, throwable: Throwable? = null, tag: String? = null) { log(LogLevel.VERBOSE, tag, throwable, message) } @@ -73,7 +73,7 @@ object Napier { * @param message Lambda: The message you would like logged. This value cannot be null. */ fun v(throwable: Throwable? = null, tag: String? = null, message: () -> String) { - log(LogLevel.VERBOSE, tag, throwable, message()) + log(LogLevel.VERBOSE, tag, throwable, message) } /** Send a INFO log message and log the exception. @@ -83,7 +83,7 @@ object Napier { * @param tag String: Used to identify the source of a log message. It usually * identifies the class or activity where the log call occurs. This value may be null. */ - fun i(message: String, throwable: Throwable? = null, tag: String? = null) { + fun i(message: String?, throwable: Throwable? = null, tag: String? = null) { log(LogLevel.INFO, tag, throwable, message) } @@ -95,7 +95,7 @@ object Napier { * @param message Lambda: The message you would like logged. This value cannot be null. */ fun i(throwable: Throwable? = null, tag: String? = null, message: () -> String) { - log(LogLevel.INFO, tag, throwable, message()) + log(LogLevel.INFO, tag, throwable, message) } /** Send a DEBUG log message and log the exception. @@ -105,7 +105,7 @@ object Napier { * @param tag String: Used to identify the source of a log message. It usually * identifies the class or activity where the log call occurs. This value may be null. */ - fun d(message: String, throwable: Throwable? = null, tag: String? = null) { + fun d(message: String?, throwable: Throwable? = null, tag: String? = null) { log(LogLevel.DEBUG, tag, throwable, message) } @@ -117,7 +117,7 @@ object Napier { * @param message Lambda: The message you would like logged. This value cannot be null. */ fun d(throwable: Throwable? = null, tag: String? = null, message: () -> String) { - log(LogLevel.DEBUG, tag, throwable, message()) + log(LogLevel.DEBUG, tag, throwable, message) } /** Send a WARN log message and log the exception. @@ -127,7 +127,7 @@ object Napier { * @param tag String: Used to identify the source of a log message. It usually * identifies the class or activity where the log call occurs. This value may be null. */ - fun w(message: String, throwable: Throwable? = null, tag: String? = null) { + fun w(message: String?, throwable: Throwable? = null, tag: String? = null) { log(LogLevel.WARNING, tag, throwable, message) } @@ -139,7 +139,7 @@ object Napier { * @param message Lambda: The message you would like logged. This value cannot be null. */ fun w(throwable: Throwable? = null, tag: String? = null, message: () -> String) { - log(LogLevel.WARNING, tag, throwable, message()) + log(LogLevel.WARNING, tag, throwable, message) } /** Send a ERROR log message and log the exception. @@ -149,7 +149,7 @@ object Napier { * @param tag String: Used to identify the source of a log message. It usually * identifies the class or activity where the log call occurs. This value may be null. */ - fun e(message: String, throwable: Throwable? = null, tag: String? = null) { + fun e(message: String?, throwable: Throwable? = null, tag: String? = null) { log(LogLevel.ERROR, tag, throwable, message) } @@ -161,7 +161,7 @@ object Napier { * @param message Lambda: The message you would like logged. This value cannot be null. */ fun e(throwable: Throwable? = null, tag: String? = null, message: () -> String) { - log(LogLevel.ERROR, tag, throwable, message()) + log(LogLevel.ERROR, tag, throwable, message) } /** What a Terrible Failure: Report an exception that should never happen. @@ -171,7 +171,7 @@ object Napier { * @param tag String: Used to identify the source of a log message. It usually * identifies the class or activity where the log call occurs. This value may be null. */ - fun wtf(message: String, throwable: Throwable? = null, tag: String? = null) { + fun wtf(message: String?, throwable: Throwable? = null, tag: String? = null) { log(LogLevel.ASSERT, tag, throwable, message) } @@ -183,7 +183,7 @@ object Napier { * @param message Lambda: The message you would like logged. This value cannot be null. */ fun wtf(throwable: Throwable? = null, tag: String? = null, message: () -> String) { - log(LogLevel.ASSERT, tag, throwable, message()) + log(LogLevel.ASSERT, tag, throwable, message) } /** Low-level logging call. @@ -199,13 +199,33 @@ object Napier { priority: LogLevel, tag: String? = null, throwable: Throwable? = null, - message: String + message: String? ) { if (isEnable(priority, tag)) { rawLog(priority, tag, throwable, message) } } + /** Low-level logging call. + * + * @param priority enum: The priority/type of this log message Value is ASSERT, + * ERROR, WARN, INFO, DEBUG, or VERBOSE + * @param tag String: Used to identify the source of a log message. It usually + * identifies the class or activity where the log call occurs. This value may be null. + * @param throwable Throwable: An exception to log This value may be null. + * @param message String: The message you would like logged. This value cannot be null. + */ + fun log( + priority: LogLevel, + tag: String? = null, + throwable: Throwable? = null, + message: () -> String + ) { + if (isEnable(priority, tag)) { + rawLog(priority, tag, throwable, message()) + } + } + /** Remove antilog from the base array. */ fun takeLogarithm(antilog: Antilog) { baseArray.remove(antilog) @@ -239,5 +259,5 @@ fun log( tag: String? = null, message: () -> String, ) { - Napier.log(priority, tag, throwable, message()) + Napier.log(priority, tag, throwable, message) }