admin管理员组

文章数量:1435507

Where can I learn about the implementations of console.log? To be clear, I know HOW to use console.log(), but I want to see the underlying implementations of console.log for some of the major browsers. Does console.log just echo input back into a part of the screen? Does it save logged strings to disk when parsing js and then write it to back to the screen? etc.

Where can I learn about the implementations of console.log? To be clear, I know HOW to use console.log(), but I want to see the underlying implementations of console.log for some of the major browsers. Does console.log just echo input back into a part of the screen? Does it save logged strings to disk when parsing js and then write it to back to the screen? etc.

Share Improve this question asked May 11, 2014 at 20:40 charmander123charmander123 3673 silver badges11 bronze badges 6
  • 3 In Chromium/blink/sources/devtools clone git chromium.googlesource./chromium/blink – Benjamin Gruenbaum Commented May 11, 2014 at 20:44
  • Found a mirror of something relevant - github./mirrors/blink/blob/… , if I may ask, why do you need this information? It's just a DOM element that has text appended to in JS, there's the CodeMirror editor in the background. – Benjamin Gruenbaum Commented May 11, 2014 at 20:49
  • I'm curious if writing to console actually writes to disk or if it's all done in-memory. – charmander123 Commented May 14, 2014 at 10:19
  • For what browser? Also, just the input or also the output? – Benjamin Gruenbaum Commented May 14, 2014 at 10:20
  • Any of the major three browsers. I noticed that IE doesn't seem to display my console logging unless I have console open, but Chrome will display my console logs even if the console window wasn't initially open - which made me curious about how the console logging is implemented (either the input or the output). – charmander123 Commented May 15, 2014 at 11:01
 |  Show 1 more ment

3 Answers 3

Reset to default 1

All Console behaviour (including the algorithms that must be implemented) are defined in https://console.spec.whatwg (and if it's not in there, officially, its implementation is undefined and literally "whatever works").

For this question specifically, the behaviour as of 23 March 2021 is prescribed as:

If the console is not open when the printer operation is called, implementations should buffer messages to show them in the future up to an implementation-chosen limit (typically on the order of at least 100).

(Although of course IE is no longer nearly as relevant in 2021 as it was back in 2014, with the very last version of IE finally entering EOL on June 15, 2022)

console.log() can be used to debug variables, test if functions are being called, things along those lines, here's an example

for(i=0;i<10;i++){
  console.log(i)
}

console: 1 2 3 4 5 6 7 8 9

1 more example:

function start(){
  console.log("starting...")
  started = true
  console.log(started)
}

console: "starting..." true

I don't think this is part of any specification. You can read that and the related links : https://developer.mozilla/en-US/docs/Web/API/console.log

本文标签: javascriptHow is consolelog() implementedStack Overflow