Skip to content

Commit e85a938

Browse files
author
mazen-rashed
committed
Add Logs Listener
1 parent 6a28076 commit e85a938

File tree

7 files changed

+17
-4
lines changed

7 files changed

+17
-4
lines changed

.idea/caches/gradle_models.ser

100755100644
2.57 KB
Binary file not shown.

.idea/encodings.xml

100755100644
File mode changed.

.idea/gradle.xml

100755100644
File mode changed.

.idea/misc.xml

100755100644
File mode changed.

.idea/runConfigurations.xml

100755100644
File mode changed.

.idea/vcs.xml

100755100644
File mode changed.

lib/src/main/java/com/mazenrashed/logdnaandroidclient/LogDna.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ object LogDna {
1818
private var apiKey: String? = null
1919
var appName: String? = null
2020
var logResults = PublishRelay.create<LogResult>()
21+
var logResultsListener: ((LogResult) -> Unit)? = null
2122

2223
fun init(apiKey: String, appName: String?) {
2324
this.apiKey = apiKey
@@ -40,10 +41,16 @@ object LogDna {
4041
)
4142
.subscribeOn(Schedulers.io())
4243
.subscribe({
43-
logResults.accept(LogResult(it.isSuccessful,
44+
val logResult = LogResult(
45+
it.isSuccessful,
4446
if (it.isSuccessful) it.body()?.status!! else it.errorBody()?.string()!!,
4547
Gson().fromJson(LibUtils.bodyToString(it.raw().request().body()), LogRequest::class.java)
46-
))
48+
)
49+
50+
if (logResults.hasObservers())
51+
logResults.accept(logResult)
52+
logResultsListener?.invoke(logResult)
53+
4754
disposable.dispose()
4855
}, {
4956
it.printStackTrace()
@@ -68,10 +75,16 @@ object LogDna {
6875
)
6976
.subscribeOn(Schedulers.io())
7077
.subscribe({
71-
logResults.accept(LogResult(it.isSuccessful,
78+
val logResult = LogResult(
79+
it.isSuccessful,
7280
if (it.isSuccessful) it.body()?.status!! else it.errorBody()?.string()!!,
7381
Gson().fromJson(LibUtils.bodyToString(it.raw().request().body()), LogRequest::class.java)
74-
))
82+
)
83+
84+
if (logResults.hasObservers())
85+
logResults.accept(logResult)
86+
logResultsListener?.invoke(logResult)
87+
7588
disposable.dispose()
7689
}, {
7790
it.printStackTrace()

0 commit comments

Comments
 (0)