mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-27 09:54:32 +01:00
Add global SDK logger (#242)
* Add SDK global logger * Add bindings * Fix path to internal uniffi log * Exclude "set_log_stream" from generated RN methods * Move logger-specific structs to a separate module * Delegate init_logging to method in logger.rs * Rename uniffi BindingLogger to UniffiBindingLogger * Add set_log_stream for dart bindings * Add SDK logger to Dart bindings * Rename dart binding logger to DartBindingLogger * Add rustdocs * RN bindings: Add manual handling for setLogStream() * Re-generate dart bindings * Re-generate RN bindings * Remove LOG_INIT cell * Set global maximum log level once on initialization Return a LiquidSdkError::Generic instead of Anyhow error when initializing log stream on Dart bindings * Do not panic when initializing binding loggers * Rename LogStream to Logger --------- Co-authored-by: Erdem Yerebasmaz <erdem@yerebasmaz.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.breezliquidsdk
|
||||
|
||||
import breez_liquid_sdk.LogEntry
|
||||
import breez_liquid_sdk.Logger
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
|
||||
|
||||
class BreezLiquidSDKLogger(private val emitter: RCTDeviceEventEmitter) : Logger {
|
||||
companion object {
|
||||
var emitterName = "breezLiquidSdkLog"
|
||||
}
|
||||
|
||||
override fun log(l: LogEntry) {
|
||||
emitter.emit(emitterName, readableMapOf(l))
|
||||
}
|
||||
}
|
||||
@@ -226,6 +226,43 @@ fun asLnInvoiceList(arr: ReadableArray): List<LnInvoice> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asLogEntry(logEntry: ReadableMap): LogEntry? {
|
||||
if (!validateMandatoryFields(
|
||||
logEntry,
|
||||
arrayOf(
|
||||
"line",
|
||||
"level",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val line = logEntry.getString("line")!!
|
||||
val level = logEntry.getString("level")!!
|
||||
return LogEntry(
|
||||
line,
|
||||
level,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(logEntry: LogEntry): ReadableMap {
|
||||
return readableMapOf(
|
||||
"line" to logEntry.line,
|
||||
"level" to logEntry.level,
|
||||
)
|
||||
}
|
||||
|
||||
fun asLogEntryList(arr: ReadableArray): List<LogEntry> {
|
||||
val list = ArrayList<LogEntry>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asLogEntry(value)!!)
|
||||
else -> throw LiquidSdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPayment(payment: ReadableMap): Payment? {
|
||||
if (!validateMandatoryFields(
|
||||
payment,
|
||||
|
||||
@@ -55,6 +55,21 @@ class BreezLiquidSDKModule(reactContext: ReactApplicationContext) : ReactContext
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun setLogger(promise: Promise) {
|
||||
executor.execute {
|
||||
try {
|
||||
val emitter = reactApplicationContext.getJSModule(RCTDeviceEventEmitter::class.java)
|
||||
|
||||
setLogger(BreezLiquidSDKLogger(emitter))
|
||||
promise.resolve(readableMapOf("status" to "ok"))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun connect(
|
||||
req: ReadableMap,
|
||||
|
||||
Reference in New Issue
Block a user