Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented May 2, 2019

Builds on previous PR adding BuildConfig - guards logging statements outside of debug mode for anything less than warn.

Should not be considered until after #8821

Addresses flutter/flutter#28848

@dnfield dnfield mentioned this pull request May 2, 2019
@dnfield dnfield marked this pull request as ready for review May 3, 2019 02:06
@dnfield dnfield requested review from matthew-carroll and mklim May 3, 2019 02:06
@dnfield dnfield requested a review from sbaranov May 3, 2019 02:10
@dnfield dnfield changed the title Guard logs Guard Android logs May 3, 2019
for (SemanticsNode child : childrenInTraversalOrder) {
child.log(childIndent, recursive);
if (BuildConfig.DEBUG) {
Log.i(TAG,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Android already take care of avoiding log statements when built in release mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it can because this is a library. Either way, the linter is telling us we should be guarding this this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(specifically for logging levels below warning)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there someone who could clarify whether we need this in actuality? I've got a lot of logs in the embedding and unfortunately this is quite a tedious practice per log statement. I would definitely appreciate if we could determine with confidence what the behavior is and ideally avoid this. Another option might be to introduce our own Log class that internally contains these guards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only needed for log levels below warn. Linter clarifies it, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus we don't want to be adding more noise to logcat for informational logging outside of debug mode do we?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation says that verbose logs aren't compiled into release build, and debug logs are but are stripped at runtime. INFO statements are higher than both so would always be included, even in regular apps. I'm having trouble finding info on if this automatic stripping is different for libraries vs apps. This page on releasing your app says to manually remove Log calls, so seems like there's conflicting info floating around. I know proguard could handle this too, but we're not using it.

We could do a quick check to confirm that just logs out at every level when the engine initializes and check what gets printed with flutter run --release?

+1 to our own Log class wrapper instead of needing to guard at every call site though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not strongly opposed to that, but I think we should generally avoid informational logging in the embedder outside of temporary logs for local debugging. Creating a utility class could encourage people to add logging that we don't need.

IOW, informational logging that remains in this codebase should be painful. We only have a few callsites (some of which are already in helper classes or methods), and even of those I think two of them should be upgraded to errors or warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I say this in part because logcat is already super chatty, and we should avoid adding to chatter when you're looking for flutter specific logs)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I think requiring the callsite checks makes sense then.

for (SemanticsNode child : childrenInTraversalOrder) {
child.log(childIndent, recursive);
if (BuildConfig.DEBUG) {
Log.i(TAG,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation says that verbose logs aren't compiled into release build, and debug logs are but are stripped at runtime. INFO statements are higher than both so would always be included, even in regular apps. I'm having trouble finding info on if this automatic stripping is different for libraries vs apps. This page on releasing your app says to manually remove Log calls, so seems like there's conflicting info floating around. I know proguard could handle this too, but we're not using it.

We could do a quick check to confirm that just logs out at every level when the engine initializes and check what gets printed with flutter run --release?

+1 to our own Log class wrapper instead of needing to guard at every call site though.

Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

for (SemanticsNode child : childrenInTraversalOrder) {
child.log(childIndent, recursive);
if (BuildConfig.DEBUG) {
Log.i(TAG,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I think requiring the callsite checks makes sense then.

@matthew-carroll
Copy link
Contributor

If d() and v() logs don't require wrapping then LGTM. If they do require wrapping then I'd like to see a custom Log implementation.

@dnfield
Copy link
Contributor Author

dnfield commented May 3, 2019

Log.d, Log.v, and Log.i are all priority levels below warn. They require wrapping. I fail to see why they should ever be in a release build, and I fail to see why the codebase should contain them outside of exceptional circumstances (such as locally doing debugging). I'm concerned that a utility class will encourage developers to leave debugging logs that don't really belong.

Log.w, Log.e, and Log.wtf are priority levels that do not require wrapping.

Perhaps we can discuss offline.

@matthew-carroll
Copy link
Contributor

Yeah let's discuss offline. Developers would have to go through rounds of adding logs to debug, and then removing them all after debugging, and then doing it all over again the next time. I can't see why that's a good use of anyone's time. As I said, I have numerous logs in the embedding to track lifecycle events and other things. So let's chat in person if you really think those logs shouldn't be there.

@dnfield
Copy link
Contributor Author

dnfield commented May 3, 2019

For whateer reason, the linter is just fine with the logs in other places in the embedding. I'm not sure if that's a bug or not in the linter, but I think it's good enough for now to just guard these instances and leave it at that. Going to merge this.

@dnfield dnfield merged commit 7ce2666 into flutter:master May 3, 2019
@dnfield dnfield deleted the guard_log branch May 3, 2019 21:32
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 3, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 3, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request May 3, 2019
flutter/engine@8811392...2c9e37c

git log 8811392..2c9e37c --no-merges --oneline
2c9e37c Cause crash in FlutterJNI if invoked on non-main thread (#31263). (flutter/engine#8830)
7ce2666 Guard Android logs (flutter/engine#8824)
8584da2 Roll src/third_party/skia dc19391eef52..70aab823547a (8 commits) (flutter/engine#8836)
1cdc163 Roll src/third_party/dart 1577b95c93..dbe80f3397 (43 commits)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (amirha@google.com), and stop
the roller if necessary.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants