chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
791 stars 478 forks source link

Allow custom log handling (2) #854

Closed benthillerkus closed 7 months ago

benthillerkus commented 7 months ago

This is just #830 but squashed & rebased to master and with most of the provided feedback addressed. I didn't rename setSendLogsToDart to setLogger yet though, because even if my name was pretty clunky it was at least accurate to what's happening.

chipweinberger commented 7 months ago

using setLogger instead of setSendLogsToDart is because it is the matching native code for the setLogger call.

When you ctrl-f the code base for setLogger, you'll see all the code you need to see.

chipweinberger commented 7 months ago

this pr looks much nicer.

chipweinberger commented 7 months ago

Just as a design philosophy, FBP uses very few abstractions. If you want to see why, look at flutter_reactive_ble, where everything is abstracted. FBP took the opposite approach.

i.e.

void _log(...) {
    if (_logger == null) {
        print(...)
    } else {
        _logger(...)
    }
}

e..g

Use a custom log handler

Optionally handle all FBP logs yourself. i.e. send them to disk, another logging framework, etc.

// Note: setting a custom logger can impact perf
// due to increased platform channel usage
FlutterBluePlus.setLogger((message) {
    // your custom log handling code
});
chipweinberger commented 7 months ago

closing. It should be a minimal implementation with minimal changes.

benthillerkus commented 7 months ago

I was gonna impl those changes, but I couldn't really find the time for it in the last 2 weeks

chipweinberger commented 7 months ago

no worries. If you get around to it, feel free to do it!

I do like the idea of the PR.

By habit, I close PRs & Issues that are not "active" for awhile, as people often drop off.

chipweinberger commented 2 weeks ago

I added this in 1.34.5

FlutterBluePlus.logs