Bug 131050 - Web Inspector: Provide a way for JSContext console to log to system console
Summary: Web Inspector: Provide a way for JSContext console to log to system console
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-04-01 11:52 PDT by Joseph Pecoraro
Modified: 2014-04-04 12:58 PDT (History)
7 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (6.08 KB, patch)
2014-04-01 12:03 PDT, Joseph Pecoraro
timothy: review+
joepeck: commit-queue-
Details | Formatted Diff | Diff
[PATCH] Revised (11.22 KB, patch)
2014-04-03 14:57 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2014-04-01 11:52:08 PDT
We already have a way for a Page's console to log to the system console. We should provide a way for this to work with JSContext's console. An application user default seems reasonable. We could also make API/SPI to toggle at runtime.
Comment 1 Radar WebKit Bug Importer 2014-04-01 11:53:30 PDT
<rdar://problem/16488820>
Comment 2 Joseph Pecoraro 2014-04-01 12:03:49 PDT
Created attachment 228304 [details]
[PATCH] Proposed Fix

cq- because I haven't tested with iOS yet and I'm not sure if printf will work. It works on OS X though, so getting the general idea reviewed.
Comment 3 WebKit Commit Bot 2014-04-01 12:05:31 PDT
Attachment 228304 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/inspector/JSConsoleClient.cpp:73:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Timothy Hatcher 2014-04-01 12:14:48 PDT
Comment on attachment 228304 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=228304&action=review

> Source/JavaScriptCore/inspector/JSConsoleClient.cpp:62
> +    Boolean preference = CFPreferencesGetAppBooleanValue(CFSTR("JavaScriptCoreConsoleLogToSystemConsole"), kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat);

JavaScriptCoreConsoleLogToSystemConsole implies only console.log is printed. A verb like "output" would help too. Maybe: OutputJavaScriptCoreConsoleToSystemConsole. Does this work for WebKit too? Maybe OutputJavaScriptConsoleToSystemConsole if so.

> Source/JavaScriptCore/inspector/JSConsoleClient.cpp:82
> +    if (JSConsoleClient::logToSystemConsole())

No need for JSConsoleClient:: right?
Comment 5 Joseph Pecoraro 2014-04-01 13:23:32 PDT
(In reply to comment #4)
> (From update of attachment 228304 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=228304&action=review
> 
> > Source/JavaScriptCore/inspector/JSConsoleClient.cpp:62
> > +    Boolean preference = CFPreferencesGetAppBooleanValue(CFSTR("JavaScriptCoreConsoleLogToSystemConsole"), kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat);
> 
> JavaScriptCoreConsoleLogToSystemConsole implies only console.log is printed. A verb like "output" would help too. Maybe: OutputJavaScriptCoreConsoleToSystemConsole. Does this work for WebKit too? Maybe OutputJavaScriptConsoleToSystemConsole if so.

I want the preference to start with "JavaScriptCore" as a namespacing thing. There is one other CFPreference in JavaScriptCore and it does the same.

Any preference among these?

    - "JavaScriptCoreOutputConsoleMessagesToSystemConsole"
    - "JavaScriptCoreLogConsoleMessagesToSystemConsole"
    - "JavaScriptCoreConsoleLogToSystemConsoleEnabled"


> > Source/JavaScriptCore/inspector/JSConsoleClient.cpp:82
> > +    if (JSConsoleClient::logToSystemConsole())
> 
> No need for JSConsoleClient:: right?

Correct, but I prefer the explicit prefix because it makes it obvious that this is a static/class function and not a member function. If we have a style one way or the other I can match.
Comment 6 Timothy Hatcher 2014-04-01 13:32:47 PDT
Comment on attachment 228304 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=228304&action=review

>>> Source/JavaScriptCore/inspector/JSConsoleClient.cpp:62
>>> +    Boolean preference = CFPreferencesGetAppBooleanValue(CFSTR("JavaScriptCoreConsoleLogToSystemConsole"), kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat);
>> 
>> JavaScriptCoreConsoleLogToSystemConsole implies only console.log is printed. A verb like "output" would help too. Maybe: OutputJavaScriptCoreConsoleToSystemConsole. Does this work for WebKit too? Maybe OutputJavaScriptConsoleToSystemConsole if so.
> 
> I want the preference to start with "JavaScriptCore" as a namespacing thing. There is one other CFPreference in JavaScriptCore and it does the same.
> 
> Any preference among these?
> 
>     - "JavaScriptCoreOutputConsoleMessagesToSystemConsole"
>     - "JavaScriptCoreLogConsoleMessagesToSystemConsole"
>     - "JavaScriptCoreConsoleLogToSystemConsoleEnabled"

Prefixing with JSC makes sense. I like JavaScriptCoreOutputConsoleMessagesToSystemConsole.

>>> Source/JavaScriptCore/inspector/JSConsoleClient.cpp:82
>>> +    if (JSConsoleClient::logToSystemConsole())
>> 
>> No need for JSConsoleClient:: right?
> 
> Correct, but I prefer the explicit prefix because it makes it obvious that this is a static/class function and not a member function. If we have a style one way or the other I can match.

It looks like you are calling a base class method with this syntax. I know I have seen other static methods called without a prefix in WebCore. Not sure there is a formal style guide.
Comment 7 Joseph Pecoraro 2014-04-03 14:57:12 PDT
Created attachment 228546 [details]
[PATCH] Revised

This refactors all the printfs instead StringBuilder + WTFLogAlways. It also includes the updated default name. I tested on iOS this works (the printf would have too, but I think this is nicer).
Comment 8 WebKit Commit Bot 2014-04-03 14:58:52 PDT
Attachment 228546 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/inspector/JSConsoleClient.cpp:73:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Timothy Hatcher 2014-04-04 12:26:56 PDT
Comment on attachment 228546 [details]
[PATCH] Revised

View in context: https://bugs.webkit.org/attachment.cgi?id=228546&action=review

> Source/JavaScriptCore/inspector/JSConsoleClient.cpp:75
> +    static std::once_flag initializeLogging;
> +    std::call_once(initializeLogging, []{
> +        JSConsoleClient::initializeLogToSystemConsole();
> +    });

This makes the default behave differently than the WebKit2 equivalent setting. It can only be changed between executions, not while the app is running. That seems fine, but it might be limiting if an app needed to change it at runtime (like with a command line flag or checkbox.) The solution would require always calling CFPreferencesGetAppBooleanValue, or exposing a JSC API to change it at runtime. We can cross that bridge when needed.
Comment 10 WebKit Commit Bot 2014-04-04 12:58:13 PDT
Comment on attachment 228546 [details]
[PATCH] Revised

Clearing flags on attachment: 228546

Committed r166799: <http://trac.webkit.org/changeset/166799>
Comment 11 WebKit Commit Bot 2014-04-04 12:58:18 PDT
All reviewed patches have been landed.  Closing bug.