Adding logging

Breez SDK implements detailed logging via a streaming interface you can manage within your application. The log entries are split into several levels that you can filter and store as desired within your application, for example, by appending them to a log file.

Rust
let data_dir_path = PathBuf::from(&data_dir);
fs::create_dir_all(data_dir_path)?;

BreezServices::init_logging(&data_dir, None)?;
Swift
class SDKLogStream: LogStream {
    func log(l: LogEntry) {
        print("Received log [", l.level, "]: ", l.line)
    }
}

func logging() throws {
    try? setLogStream(logStream: SDKLogStream())
}
Kotlin
class SDKLogStream : LogStream {
    override fun log(l: LogEntry) {
        // Log.v("SDKListener", "Received log [${l.level}]: ${l.line}")
    }
}

try {
    setLogStream(SDKLogStream())
} catch (e: Exception) {
    // handle error
}
React Native
const onLogEntry = (l: LogEntry) => {
  console.log(`Received log [${l.level}]: ${l.line}`)
}

const subscription = await setLogStream(onLogEntry)
Dart
void onLogEntry(log) {
  print("Received log ${log.level}]: ${log.line}");
}

void logging(BreezSDK breezSDK) {
  breezSDK.logStream.listen(onLogEntry);
}
Python
class SDKLogStream(breez_sdk.LogStream):
    def log(self, l):
        print("Received log [", l.level, "]: ", l.line)

def logging():
    try:
        breez_sdk.set_log_stream(SDKLogStream())
    except Exception as error:
        print(error)
        raise
Go
type SdkLogStream struct{}

func (SdkLogStream) Log(l breez_sdk.LogEntry) {
    log.Printf("Received log [%v]: %v", l.Level, l.Line)
}

func GettingStartedLogging() {
    err := breez_sdk.SetLogStream(SdkLogStream{})
    if err != nil {
        log.Fatalf("SetLogStream failed: %#v", err)
    }
}

C#
public void GettingStartedLogging()
{
    try
    {
        BreezSdkMethods.SetLogStream(new SdkLogStream());
    }
    catch (Exception)
    {
        // Handle error
    }
}

class SdkLogStream : LogStream
{
    public void Log(LogEntry l)
    {
        Console.WriteLine($"Received Log [{l.level}]: {l.line}");
    }
}