RESOLVED FIXED 101495
Web Inspector: styled logs should work with multiple log() arguments
https://bugs.webkit.org/show_bug.cgi?id=101495
Summary Web Inspector: styled logs should work with multiple log() arguments
Paul Irish
Reported 2012-11-07 11:33:56 PST
Execute: console.log('%c styled', 'unstyled', 'color:red'); Only the text " styled color:red" is logged. I would expect these to work: console.log('%c red text', 'unstyled', 'color:red'); console.log(window, 'unstyled', '%c red text', 'color:red'); console.log('unstyled', document.body, '%c red text', 'color:red'); I suppose there isn't a spec's behavior here to follow, but this seems an intuitive direction.
Attachments
After. (14.39 KB, image/png)
2012-11-10 07:26 PST, Mike West
no flags
Patch (8.74 KB, patch)
2012-11-10 08:14 PST, Mike West
no flags
Patch (8.65 KB, patch)
2012-11-10 08:40 PST, Mike West
no flags
Rebased. (8.64 KB, patch)
2012-11-10 08:46 PST, Mike West
no flags
Hrm. (8.64 KB, patch)
2012-11-10 11:19 PST, Mike West
no flags
Patch for landing (8.70 KB, patch)
2012-11-10 15:40 PST, Mike West
no flags
Pavel Feldman
Comment 1 2012-11-07 12:21:01 PST
> I would expect these to work: > > console.log('%c red text', 'unstyled', 'color:red'); > console.log(window, 'unstyled', '%c red text', 'color:red'); > console.log('unstyled', document.body, '%c red text', 'color:red'); Here is the message formatting logic: when there are multiple arguments, if the first argument is a string, it is considered a "message format". message format string absorbes parameter per %X occurrence. So you should not expect the onces above to work.
Jan Honza Odvarko
Comment 2 2012-11-08 07:52:58 PST
(In reply to comment #1) > > I would expect these to work: > > > > console.log('%c red text', 'unstyled', 'color:red'); > > console.log(window, 'unstyled', '%c red text', 'color:red'); > > console.log('unstyled', document.body, '%c red text', 'color:red'); > > Here is the message formatting logic: when there are multiple arguments, if > the first argument is a string, it is considered a "message format". message > format string absorbes parameter per %X occurrence. Agree FWG had a similar discussion about styling parts of the log output, e.g. make only part of the log red or green. What about using the following concept: console.log('%c red-text %c green-text', 'color:red', 'color:green'); Honza
Pavel Feldman
Comment 3 2012-11-09 04:21:15 PST
> console.log('%c red-text %c green-text', 'color:red', 'color:green'); This matches the formatting logic well, so sure, why not.
Jan Honza Odvarko
Comment 4 2012-11-09 05:17:41 PST
(In reply to comment #3) > > console.log('%c red-text %c green-text', 'color:red', 'color:green'); > > This matches the formatting logic well, so sure, why not. Excellent, patch for Firebug committed at: https://github.com/firebug/firebug/commit/7d6f7e951f9222d8c8f5252c148d84e072f4bb18 Related issue report: http://code.google.com/p/fbug/issues/detail?id=6064 Honza
Mike West
Comment 5 2012-11-09 05:22:26 PST
I'll take this at some point in the relatively near future.
Mike West
Comment 6 2012-11-10 07:26:35 PST
Mike West
Comment 7 2012-11-10 07:27:42 PST
(In reply to comment #6) > Created an attachment (id=173452) [details] > After. The work is trivial; I just need to change the tests. Should have a patch up in an hour or so (compiling === slow at home :( ).
Mike West
Comment 8 2012-11-10 08:14:22 PST
Pavel Feldman
Comment 9 2012-11-10 08:26:17 PST
Comment on attachment 173453 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=173453&action=review > Source/WebCore/inspector/front-end/ConsoleMessage.js:477 > + var currentStyle = {}; You probably mean var currentStyle = null; here. > Source/WebCore/inspector/front-end/ConsoleMessage.js:523 > + if (currentStyle.hasOwnProperty(key)) You don't need this check: enumerable properties on the object created with {} is what you need. > LayoutTests/inspector/console/console-format-style.html:9 > + console.log('%cRed! %cRed!', 'color: blue;', 'color: red;'); %cBlue! %cRed!
Mike West
Comment 10 2012-11-10 08:40:22 PST
Mike West
Comment 11 2012-11-10 08:41:35 PST
(In reply to comment #9) > (From update of attachment 173453 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=173453&action=review > > > Source/WebCore/inspector/front-end/ConsoleMessage.js:477 > > + var currentStyle = {}; > > You probably mean var currentStyle = null; here. Sure. That's slightly faster. > > Source/WebCore/inspector/front-end/ConsoleMessage.js:523 > > + if (currentStyle.hasOwnProperty(key)) > > You don't need this check: enumerable properties on the object created with {} is what you need. Habit. But you're right; I'll drop it. > > LayoutTests/inspector/console/console-format-style.html:9 > > + console.log('%cRed! %cRed!', 'color: blue;', 'color: red;'); > > %cBlue! %cRed! %cCopy! %cPaste! %cError! :) Thanks!
Mike West
Comment 12 2012-11-10 08:46:05 PST
Created attachment 173455 [details] Rebased.
Pavel Feldman
Comment 13 2012-11-10 10:06:03 PST
Comment on attachment 173455 [details] Rebased. View in context: https://bugs.webkit.org/attachment.cgi?id=173455&action=review Thanks! > Source/WebCore/inspector/front-end/ConsoleMessage.js:480 > + var currentStyle = null; It is not that it is now faster. It is that otherwise your code was wrong and was wrapping everything.
WebKit Review Bot
Comment 14 2012-11-10 10:41:10 PST
Comment on attachment 173455 [details] Rebased. Attachment 173455 [details] did not pass chromium-ews (chromium-xvfb): Output: http://queues.webkit.org/results/14796347 New failing tests: inspector/console/console-format-style-whitelist.html
Mike West
Comment 15 2012-11-10 11:19:28 PST
Mike West
Comment 16 2012-11-10 11:20:52 PST
Comment on attachment 173460 [details] Hrm. Carrying over r+. Not sure why the bots didn't like the patch. Reuploading it after changing a line of the expectations that I can't explain ('text-decoration: none;' -> 'text-decoration: initial;')
Mike West
Comment 17 2012-11-10 11:21:23 PST
(In reply to comment #13) > (From update of attachment 173455 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=173455&action=review > > Thanks! > > > Source/WebCore/inspector/front-end/ConsoleMessage.js:480 > > + var currentStyle = null; > > It is not that it is now faster. It is that otherwise your code was wrong and was wrapping everything. You're right. I'd convinced myself that an empty object was falsey. :( Thanks!
Mike West
Comment 18 2012-11-10 15:40:06 PST
Created attachment 173480 [details] Patch for landing
WebKit Review Bot
Comment 19 2012-11-10 16:21:01 PST
Comment on attachment 173480 [details] Patch for landing Clearing flags on attachment: 173480 Committed r134166: <http://trac.webkit.org/changeset/134166>
WebKit Review Bot
Comment 20 2012-11-10 16:21:06 PST
All reviewed patches have been landed. Closing bug.
eustas.bug
Comment 21 2012-11-12 00:04:55 PST
Comment on attachment 173480 [details] Patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=173480&action=review > Source/WebCore/inspector/front-end/ConsoleMessage.js:525 > + for (key in currentStyle) Should be "for (var key in currentStyle)"
Mike West
Comment 22 2012-11-12 00:30:33 PST
(In reply to comment #21) > (From update of attachment 173480 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=173480&action=review > > > Source/WebCore/inspector/front-end/ConsoleMessage.js:525 > > + for (key in currentStyle) > > Should be "for (var key in currentStyle)" Oops. You are entirely correct: https://bugs.webkit.org/show_bug.cgi?id=101908
Note You need to log in before you can comment on or make changes to this bug.