-
Notifications
You must be signed in to change notification settings - Fork 23
[proposal] enhanced on-demand logging #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I do think we should give strong consideration to a "fresh start" with The current API here suffers a few flaws that are not easy to fix:
We had strongly considered moving away from At this point the migration cost for the ecosystem would be huge, but it's still cheaper now that it ever will be again as we pile on more use. |
Thanks for the perspective @natebosch! I'd be curious to hear more about your experience with
|
Capturing some more thoughts for the future:
A
There is a relatively easy workaround of logging an object with a cheap In general I think it is best to keep this package tightly focused on what it does today - plumbing the records through to a listener, filtering by level, and allowing for lazy message evaluation for cases where building the string is expensive. If it does make sense to be opinionated about log listeners - printing, writing to a file, managing across isolates etc, that should be handled in hopefully a separate package. The "write a log" use case is way more widespread than the "handle a log" use case - the former should see very few breaking changes while the latter can likely handle a bit more churn. It's also likely, IMO, that use cases are too specific to get a lot of value out of a shared package. |
Another thing to consider - whether we can find a design that is easy to tree-shake: #424 |
Proposal: Enhanced On-Demand Logging
We’ve been exploring enhanced logging in Flutter, the IntelliJ plugin and most recently in a separate package and have been encouraged by a bunch of early partner feedback. The idea hinges on treating named loggers as channels (or streams) that can be enabled and disabled on-demand via a VM service extension, allowing for configuration from clients such as IDEs or programmatically in application source.
In source, enabling named loggers looks as simple as:
and in an IDE like this:
The current
package:logging
can be simply enhanced to support enhanced on-demand logging in an entirely API-compatible way.Background
flutter/flutter#21504 proposes a light-weight logging framework for Flutter and flutter/flutter#22041 offers one possible implementation and a bit more context. Finally, the logs package (unpublished) approaches the feature more generally as something that transcends Flutter and is more generally useful in Dart.
Some learnings:
With these experiences in mind, we’d like to consider adding some simple facilities to the
logging
package. We think these ideas extend logging but don’t change it’s spirit. The benefits are ergonomics, functionality and potential for rich tool integration. Withpackage:logging
enhanced, we would not need to a new package (e.g.,logs
) or to land any new logging frameworks bits into Flutter foundation.Implementation
Specifically, we’re proposing a log manager (or similar abstraction)
(Secondarily, we’d like to formally expand the
error
message field to embrace “data” more generally.)It’s important to note that this proposal involves NO breaking API and will leave current uses of logging facilities totally unaffected.
Use Cases
Tooling Use Case: queries (for tool integration)
IDEs (and other tools), should be able to query an app for all available loggers. Ideally, loggers could provide descriptions to help developers know what they do and why they might want to enable them.
example:
Susan is developing a flutter app and decides to try the redux package. She adds the package to her pubspec and follows the example but is confused by what’s happening. To help, she goes to the logging view and opens a "logger/channel chooser” dialog that enumerates the available loggers for her app. There are a bunch but descriptions help her identify a few to toggle that log redux lifecycle events. After playing around with her app and some sample code she’s confident she has the basic idea and disables logging.
API Use Case: programmatic enablement
Developers should be able to programmatically enabling logging channels (and not depend entirely on clients like IDEs).
example:
Sometimes Susan likes to just use vim and run her flutter app in the terminal. Turning on logging is handy for debugging so she’s happy to be able to enable it w/ a line in her app’s main.
Application Use Case: networking traffic
The user would like to view (and potentially troubleshoot) the networking traffic of their app. They either:
We then show http call start and stops, with http header and payload information available (ala Chrome DevTools). The implementation might work by replacing the dart:io
HttpClient
class (via the global override) with an implementation that logged http traffic to interested clients.Application Use Case: (flutter) platform channels
This would be for either 1) users consuming an existing plugin (battery status; geo notifications), or 2) developers building a new native plugin. The user would go to the Logging view, toggle the ‘platform channel’ checkbox, and see all the JSON traffic going back and forth over the platform channel.
Application Use Case: package redux
User enables redux logs via a toggle in the logging view (an enhanced
package:redux_logging
sends redux logs to a logging stream). The user can then see the stream of state changes for their app, and, in the far-flung future, interact with them in some way to roll their app’s state backwards and forwards (a time-travelling state debugger).Other Applications
Image Cache. Logging could provide insights into Flutter’s Image Caching system. Potential events of interest include Growing and flushing cache; it may also be interesting to call out exceptionally large images.
UI performance. Logged events might complement existing timeline and inspector views by providing insights into things like:
Battery Use. (on iOS corresponding to
UIDeviceBatteryStateDidChangeNotification
events.)The text was updated successfully, but these errors were encountered: