Skip to content
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

fix: Removed redundent logcat print #950

Merged
merged 1 commit into from
Apr 12, 2020

Conversation

breautek
Copy link
Contributor

Platforms affected

Android

Motivation and Context

The chromium webview will print an informational log already,
we don't need to override the method to do what the webview will already.
Closes #914

Description

Simply removes the onConsoleMessage message override, since we don't do anything other than to print a logcat message out, which the super class already does, resulting in duplicate logcat prints.

Testing

Ran npm test and ensured all existing tests passes.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

The chromium webview will print an informational log already,
we don't need to override the method to do what the webview will already.
@breautek breautek requested a review from erisu April 12, 2020 01:20
@breautek breautek merged commit 6d451bc into apache:master Apr 12, 2020
@stochmalm
Copy link

stochmalm commented Sep 28, 2020

After upgrade to cordova android 9.0.0 I'm unable to see any logs from console.log. Isn't this related to this fix? Upgrading cordova was the only thing that I have done and now I must use alert() for debugging ._.

Tested on Android 10, Xiaomi MI 10 SE.

@breautek
Copy link
Contributor Author

breautek commented Sep 28, 2020

After upgrade to cordova android 9.0.0 I'm unable to see any logs from console.log. Isn't this related to this fix? Upgrading cordova was the only thing that I have done and now I must use alert() for debugging ._.

Tested on Android 10, Xiaomi MI 10 SE.

return super.onConsoleMessage(consoleMessage); would have produced console log messages similar to what Cordova did in the override. But it may be in a different format and definitely under a different log tag.

now I must use alert() for debugging ._.

Using logcat is mainly used for native debugging. Debugging cordova apps you should use the web inspector tools provided by Chrome (for android), or Safari for ios apps. It provides much more robust console API than logcat, + you get your JS breakpoints and other debugging tools. See Remote Debugging webviews for more information how to do this for the Chrome webview.

@breautek breautek deleted the fix/produce-one-logcat-msg branch September 28, 2020 13:56
@lomchik
Copy link

lomchik commented Sep 30, 2020

Hi. This commit breaks logging in release mode which is very useful for bug reports.

Reason:

webView print logs only when WebView.setWebContentsDebuggingEnabled(true). It is enabled here

I propose to add instead of this method something like this.

    @Override
    public boolean onConsoleMessage(ConsoleMessage consoleMessage)
    {
        if (!ApplicationInfo.FLAG_DEBUGGABLE && consoleMessage.message() != null)
            LOG.d(LOG_TAG, "%s: Line %d : %s" , consoleMessage.sourceId() , consoleMessage.lineNumber(), consoleMessage.message());
        return super.onConsoleMessage(consoleMessage);
    }

@stochmalm
Copy link

stochmalm commented Sep 30, 2020

Using logcat is mainly used for native debugging. Debugging cordova apps you should use the web inspector tools provided by Chrome (for android), or Safari for ios apps. It provides much more robust console API than logcat, + you get your JS breakpoints and other debugging tools. See Remote Debugging webviews for more information how to do this for the Chrome webview.

I had a very specific error in my app only on release build for android in which remote debugging is not available ;). Finally I reverted cordova-android back to 8.1.0 and now logging works properly.

But it may be in a different format and definitely under a different log tag.

Console logs weren't under different tag - I was using logcat without grepping.

@breautek
Copy link
Contributor Author

@lomchik

I see. I'd support a PR that re-adds console logging if the app is in release mode and if the app is in debug mode, then fall back to the super.call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleaner Logging for Android Studio
4 participants