Skip to content

Commit 36f7254

Browse files
authored
Allow null throwable when logging errors (#28)
1 parent 225a624 commit 36f7254

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

stream-log/api/android/stream-log.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public final class io/getstream/log/StreamLog {
7878
public static final fun d (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
7979
public static final fun e (Ljava/lang/String;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;)V
8080
public static final fun e (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
81+
public static synthetic fun e$default (Ljava/lang/String;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
8182
public final fun getInternalLogger ()Lio/getstream/log/StreamLogger;
8283
public final fun getInternalValidator ()Lio/getstream/log/IsLoggableValidator;
8384
public static final fun getLogger (Ljava/lang/String;)Lio/getstream/log/TaggedLogger;
@@ -113,6 +114,7 @@ public final class io/getstream/log/TaggedLogger {
113114
public final fun d (Lkotlin/jvm/functions/Function0;)V
114115
public final fun e (Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;)V
115116
public final fun e (Lkotlin/jvm/functions/Function0;)V
117+
public static synthetic fun e$default (Lio/getstream/log/TaggedLogger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
116118
public final fun getDelegate ()Lio/getstream/log/StreamLogger;
117119
public final fun getTag ()Ljava/lang/String;
118120
public final fun getValidator ()Lio/getstream/log/IsLoggableValidator;

stream-log/api/jvm/stream-log.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public final class io/getstream/log/StreamLog {
7676
public static final fun d (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
7777
public static final fun e (Ljava/lang/String;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;)V
7878
public static final fun e (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
79+
public static synthetic fun e$default (Ljava/lang/String;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
7980
public final fun getInternalLogger ()Lio/getstream/log/StreamLogger;
8081
public final fun getInternalValidator ()Lio/getstream/log/IsLoggableValidator;
8182
public static final fun getLogger (Ljava/lang/String;)Lio/getstream/log/TaggedLogger;
@@ -111,6 +112,7 @@ public final class io/getstream/log/TaggedLogger {
111112
public final fun d (Lkotlin/jvm/functions/Function0;)V
112113
public final fun e (Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;)V
113114
public final fun e (Lkotlin/jvm/functions/Function0;)V
115+
public static synthetic fun e$default (Lio/getstream/log/TaggedLogger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
114116
public final fun getDelegate ()Lio/getstream/log/StreamLogger;
115117
public final fun getTag ()Ljava/lang/String;
116118
public final fun getValidator ()Lio/getstream/log/IsLoggableValidator;

stream-log/src/commonMain/kotlin/io/getstream/log/StreamLog.kt

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import io.getstream.log.Priority.INFO
2222
import io.getstream.log.Priority.VERBOSE
2323
import io.getstream.log.Priority.WARN
2424
import kotlin.concurrent.Volatile
25+
import kotlin.jvm.JvmOverloads
2526
import kotlin.jvm.JvmStatic
2627

2728
/**
@@ -112,25 +113,13 @@ public object StreamLog {
112113
* @param message The function returning a message you would like logged.
113114
*/
114115
@JvmStatic
115-
public inline fun e(tag: String, throwable: Throwable, message: () -> String) {
116+
@JvmOverloads
117+
public inline fun e(tag: String, throwable: Throwable? = null, message: () -> String) {
116118
if (internalValidator.isLoggable(ERROR, tag)) {
117119
internalLogger.log(ERROR, tag, message(), throwable)
118120
}
119121
}
120122

121-
/**
122-
* Send a [ERROR] log message.
123-
*
124-
* @param tag Used to identify the source of a log message.
125-
* @param message The function returning a message you would like logged.
126-
*/
127-
@JvmStatic
128-
public inline fun e(tag: String, message: () -> String) {
129-
if (internalValidator.isLoggable(ERROR, tag)) {
130-
internalLogger.log(ERROR, tag, message())
131-
}
132-
}
133-
134123
/**
135124
* Send a [WARN] log message.
136125
*
@@ -206,17 +195,13 @@ public object StreamLog {
206195
*/
207196
@JvmStatic
208197
public inline fun log(priority: Priority, tag: String, throwable: Throwable? = null, message: () -> String) {
209-
if (throwable != null) {
210-
e(tag, throwable, message)
211-
} else {
212-
when (priority) {
213-
VERBOSE -> v(tag, message)
214-
DEBUG -> d(tag, message)
215-
INFO -> i(tag, message)
216-
WARN -> w(tag, message)
217-
ERROR -> e(tag, message)
218-
ASSERT -> a(tag, message)
219-
}
198+
when (priority) {
199+
VERBOSE -> v(tag, message)
200+
DEBUG -> d(tag, message)
201+
INFO -> i(tag, message)
202+
WARN -> w(tag, message)
203+
ERROR -> e(tag, throwable, message)
204+
ASSERT -> a(tag, message)
220205
}
221206
}
222207
}
@@ -250,23 +235,13 @@ public class TaggedLogger(
250235
* @param throwable An exception to log.
251236
* @param message The function returning a message you would like logged.
252237
*/
253-
public inline fun e(throwable: Throwable, message: () -> String) {
238+
@JvmOverloads
239+
public inline fun e(throwable: Throwable? = null, message: () -> String) {
254240
if (validator.isLoggable(ERROR, tag)) {
255241
delegate.log(ERROR, tag, message(), throwable)
256242
}
257243
}
258244

259-
/**
260-
* Send a [ERROR] log message.
261-
*
262-
* @param message The function returning a message you would like logged.
263-
*/
264-
public inline fun e(message: () -> String) {
265-
if (validator.isLoggable(ERROR, tag)) {
266-
delegate.log(ERROR, tag, message())
267-
}
268-
}
269-
270245
/**
271246
* Send a [WARN] log message.
272247
*

0 commit comments

Comments
 (0)