Skip to content

Commit

Permalink
Apply filter level changes to Flutter plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemyerebasmaz committed Mar 23, 2024
1 parent 492f08c commit 086d763
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BreezSDKPlugin : FlutterPlugin, MethodCallHandler, EventChannel.StreamHand
channel.setMethodCallHandler(this)

eventChannel = EventChannel(flutterPluginBinding.binaryMessenger, "breez_sdk_node_logs")
val nodeLogStream = SdkLogInitializer.initializeNodeLogStream()
val nodeLogStream = SdkLogInitializer.initializeNodeLogStream(null)
nodeLogStream.subscribe(scope) { l: LogEntry ->
val data = mapOf("level" to l.level, "line" to l.line)
eventSink?.success(data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.breez.breez_sdk

import breez_sdk.setLogStream
import breez_sdk.LevelFilter
import kotlinx.coroutines.CoroutineScope

object SdkLogInitializer {
private var nodeLogStream: SdkLogListener? = null

fun initializeNodeLogStream(): SdkLogListener {
fun initializeNodeLogStream(filterLevel: LevelFilter?): SdkLogListener {
if (nodeLogStream == null) {
try {
nodeLogStream = SdkLogListener()
setLogStream(nodeLogStream!!)
setLogStream(nodeLogStream!!, filterLevel)
} catch (e: Throwable) {
// Reset nodeLogStream if setting log stream fails
e.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class SdkLogListener : LogStream {
private val logEvents: SharedFlow<LogEntry> = _logEvents.asSharedFlow()

override fun log(l: LogEntry) {
scope.launch {
_logEvents.emit(l)
}
scope.launch { _logEvents.emit(l) }
}

fun subscribe(scope: CoroutineScope, block: suspend (LogEntry) -> Unit) =
Expand Down
8 changes: 4 additions & 4 deletions libs/sdk-flutter/lib/breez_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class BreezSDK {
Stream<Payment> get paymentResultStream => _paymentResultStream.stream;

/// Initializes SDK events & log streams
void initialize() {
void initialize({LevelFilter? filterLevel}) {
_initializeEventsStream();
_initializeLogStream();
_initializeLogStream(filterLevel: filterLevel);
}

/// Listen to BreezEvent's(new block, invoice paid, synced)
Expand Down Expand Up @@ -62,7 +62,7 @@ class BreezSDK {
}

/// Listen to node logs
void _initializeLogStream() {
void _initializeLogStream({LevelFilter? filterLevel}) {
if (defaultTargetPlatform == TargetPlatform.android) {
const EventChannel('breez_sdk_node_logs')
.receiveBroadcastStream()
Expand All @@ -72,7 +72,7 @@ class BreezSDK {
onError: (e) => _logStreamController.addError(e),
);
} else {
_lnToolkit.breezLogStream().listen((logEntry) {
_lnToolkit.breezLogStream(filterLevel: filterLevel).listen((logEntry) {
_logStreamController.add(logEntry);
}, onError: (e) {
_logStreamController.addError(e);
Expand Down

0 comments on commit 086d763

Please sign in to comment.