Allow clients to provide a custom logger instance#159
Conversation
jhutarek
left a comment
There was a problem hiding this comment.
Thanks! I'd consider a couple of tweaks. 🙏
|
I started a draft PR to update the website here: hotwired/hotwire-native-site#91 |
* main: Add Session tests to cover visits with restorationIdentifier logic Fix restorationIdentifier + "restore" logic so that "replace" visit actions don't get unintentionally rewritten Fix test formatting Bring back the synethic current visit restore approach, since turbo.js does not always play nicely with same-page "restore" visits Fix documentation Maintain same-page "restore" visits and dispatch a custom event so the web bridge library can be notified when this occurs Fix restoring a web visit after visiting a native screen by manually caching a snapshot when leavin the web screen.
…t what the application wants logged. This also allows consumers to change the log level without writing a full custom logger implementation.
|
@mbarta @jhutarek Please take a look at the latest changes. By introducing a |
|
Happy with the latest changes @jayohms! It's closer to a standard logger implementation where you can set the desired log level for the default logger while still being able to provide your own if more customisation is needed 👍 Thanks! |
* main: (44 commits) Add remaining code documentation for the HotwireBottomNavigationController Cleanup Check if isGraphInitialized in the host's isReady() function Improve the internal APIs for letting lazy navigator hosts Remove the intent trust gate and sanitize unconditionally Make the initControllerGraph() function private and add an explicit resetControllerGraph() Update the api name in the demo Change load load flag name Initial work to defer lazy-loaded NavigatorHost tabs until they're initially selected Gate deep-link sanitization on the launching intent's origin Validate deep-link args when resolving the start location Fix unhandled exceptions in route decision handlers Make WebView permission requests cancellation-safe Handle WebView media-capture permission requests in a delegate Use lowercase log event keys for consistency with other logging Remove unneeded CoroutinesTestRule Make PathConfiguration have an internal constructor since using it outside of the global instance is an error Upgrade OkHttp and implement the okhttp-coroutines dependency so fetching the remote configuration is cancellable Use sealed interfaces to simplify state setup Cancel the previous job before loading the bundled/cached config ... # Conflicts: # demo/src/main/kotlin/dev/hotwire/demo/DemoApplication.kt
Summary
This branch replaces Hotwire Native's built-in, Logcat-only logging with a pluggable logging system. Previously the library logged directly to Android's Logcat and only offered a single on/off switch (
debugLoggingEnabled) to control debug output. Apps had no way to capture library logs, route them to their own logging/crash-reporting stack, or control verbosity.Now the library logs through a
HotwireLoggerinterface. Apps can either keep the built-in default (which prints to Logcat), adjust the log level, or supply their own implementation to handle log messages however they like.What changed
HotwireLoggerinterface plus aHotwireLogLevelenum for filtering by severity.DefaultHotwireLoggerthat prints to Logcat, used automatically unless an app opts out.Public API changes
Removed
Hotwire.config.debugLoggingEnabled— the boolean flag no longer exists. Behavior is now controlled through the logger and its log level instead.Added
Hotwire.config.logger: HotwireLogger— set this to provide a custom logger. Defaults toDefaultHotwireLogger.HotwireLoggerinterface (public, implementable by apps).HotwireLogLevelenum:VERBOSE,DEBUG,INFO,WARN,ERROR,NONE.DefaultHotwireLogger— the built-in Logcat implementation.Migration: replace
Hotwire.config.debugLoggingEnabled = BuildConfig.DEBUGwith a log-level assignment, e.g.:The
HotwireLoggerinterfaceApps can implement this interface to receive every log message the library produces and handle it however they want — forward to their own logger, send to a crash reporter, filter, or drop entirely.
Notes on the design:
logLevellets consumers set a minimum severity. Setting it toNONEsilences all output. The default logger uses this to decide what reaches Logcat, and custom loggers are expected to honor it too.() -> String) so that potentially expensive log strings are only built when the message will actually be emitted.Throwableso exceptions can be logged with full context.To use a custom logger: