alnitak / flutter_soloud

Flutter low-level audio plugin using SoLoud C++ library and FFI
MIT License
209 stars 21 forks source link

Switch from printing to logging #32

Closed filiph closed 6 months ago

filiph commented 6 months ago

Description

The package is quite verbose and loud in the console. This PR switches it to use the standard package:logging.

This means that the developer can choose what to do with the logs: they can ignore the completely, they can only listen to the more important ones, they can route them to services such as Sentry.io or Crashlytics, and so on.

It also means the developer will see their logs in a slightly more structured way. This is how they look in DevTools, for example:

Screenshot 2024-03-07 at 20 44 20

One thing that's missing is logging from inside the audio isolate. We'd have to send logs to the main isolate through an event, which might be too expensive and brittle. I think it's okay to keep using debugPrint in audio_isolate.dart when working on the package. (Messages printed to console like that will be shown in the console β€” I'm guessing Dart creates a backchannel between the isolates for these.)

Type of Change

filiph commented 6 months ago

I was not able to run tests on my computer. I tried this:

$ cd example
$ flutter test tests/tests.dart

I got an FFI error:

% flutter test tests/tests.dart 
Resolving dependencies... 
  ...
Got dependencies!
15 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
00:05 +0: loading /Users/filiph/dev/flutter_soloud/example/tests/tests.dart
Shell: [ERROR:flutter/runtime/dart_isolate.cc(1107)] Unhandled exception:
Shell: Invalid argument(s): Failed to lookup symbol 'initEngine': dlsym(RTLD_DEFAULT, initEngine): symbol not found
Shell: #0      DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:33:70)
Shell: #1      FlutterSoLoudFfi._initEnginePtr (package:flutter_soloud/src/flutter_soloud_bindings_ffi.dart:100:56)
Shell: #2      FlutterSoLoudFfi._initEnginePtr (package:flutter_soloud/src/flutter_soloud_bindings_ffi.dart)
Shell: #3      FlutterSoLoudFfi._initEngine (package:flutter_soloud/src/flutter_soloud_bindings_ffi.dart:101:28)
Shell: #4      FlutterSoLoudFfi._initEngine (package:flutter_soloud/src/flutter_soloud_bindings_ffi.dart)
Shell: #5      FlutterSoLoudFfi.initEngine (package:flutter_soloud/src/flutter_soloud_bindings_ffi.dart:96:32)
Shell: #6      audioIsolate.<anonymous closure> (package:flutter_soloud/src/audio_isolate.dart:103:48)
Shell: #7      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
Shell: #8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
Shell: #9      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
Shell: #10     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
Shell: #11     _StreamController._add (dart:async/stream_controller.dart:658:7)
Shell: #12     _StreamController.add (dart:async/stream_controller.dart:606:5)
Shell: #13     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
alnitak commented 6 months ago

I was not able to run tests on my computer.

Oh yes, I didn't mention this. That test is not a real test that uses pkg:flutter_test. It should be run as a normal app:

$ cd example
$ flutter run tests/tests.dart

and see the console logs. Those are just 3 simple tests that try to play some waveform, a load/seek/play/pause, and concurrently play a bunch of sounds to see if some error is thrown.