Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions napier/src/commonMain/kotlin/io/github/aakira/napier/Napier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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.
Expand All @@ -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)
}

Expand All @@ -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.
Expand All @@ -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)
}

Expand All @@ -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.
Expand All @@ -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)
}

Expand All @@ -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.
Expand All @@ -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)
}

Expand All @@ -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.
Expand All @@ -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)
}

Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -239,5 +259,5 @@ fun log(
tag: String? = null,
message: () -> String,
) {
Napier.log(priority, tag, throwable, message())
Napier.log(priority, tag, throwable, message)
}