-
Notifications
You must be signed in to change notification settings - Fork 6k
Guard Android logs #8824
Guard Android logs #8824
Conversation
| for (SemanticsNode child : childrenInTraversalOrder) { | ||
| child.log(childIndent, recursive); | ||
| if (BuildConfig.DEBUG) { | ||
| Log.i(TAG, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
mklim
left a comment
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
|
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. |
|
Perhaps we can discuss offline. |
|
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. |
|
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. |
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.
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