<p dir="auto">Currently in a debugger session, console.log etc will not show by default.<br>
Some debuggers can pipe output, though this will be less featureful and not as readily available as channeling through the debugger protocol.</p>
<p dir="auto">V8 has a builtin console that is "debugger protocol" enabled, resulting in messages like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Client &lt; {&quot;method&quot;:&quot;Console.messageAdded&quot;,&quot;params&quot;:{&quot;message&quot;:{&quot;source&quot;:&quot;console-api&quot;,&quot;level&quot;:&quot;log&quot;,&quot;text&quot;:&quot;Adding  1 2&quot;,&quot;url&quot;:&quot;/home/gudmund/code/ts-test/build/index.js&quot;,&quot;line&quot;:2,&quot;column&quot;:13}}}
Client &lt; {&quot;method&quot;:&quot;Runtime.consoleAPICalled&quot;,&quot;params&quot;:{&quot;type&quot;:&quot;log&quot;,&quot;args&quot;:[{&quot;type&quot;:&quot;string&quot;,&quot;value&quot;:&quot;Adding &quot;},{&quot;type&quot;:&quot;number&quot;,&quot;value&quot;:1,&quot;description&quot;:&quot;1&quot;},{&quot;type&quot;:&quot;number&quot;,&quot;value&quot;:2,&quot;description&quot;:&quot;2&quot;}],&quot;executionContextId&quot;:1,&quot;timestamp&quot;:1587836285935.544,&quot;stackTrace&quot;:{&quot;callFrames&quot;:[{&quot;functionName&quot;:&quot;add&quot;,&quot;scriptId&quot;:&quot;54&quot;,&quot;url&quot;:&quot;file:///home/gudmund/code/ts-test/build/index.js&quot;,&quot;lineNumber&quot;:1,&quot;columnNumber&quot;:12},{&quot;functionName&quot;:&quot;&quot;,&quot;scriptId&quot;:&quot;54&quot;,&quot;url&quot;:&quot;file:///home/gudmund/code/ts-test/build/index.js&quot;,&quot;lineNumber&quot;:7,&quot;columnNumber&quot;:15},{&quot;functionName&quot;:&quot;Module._compile&quot;,&quot;scriptId&quot;:&quot;44&quot;,&quot;url&quot;:&quot;internal/modules/cjs/loader.js&quot;,&quot;lineNumber&quot;:1152,&quot;columnNumber&quot;:13},{&quot;functionName&quot;:&quot;Module._extensions..js&quot;,&quot;scriptId&quot;:&quot;44&quot;,&quot;url&quot;:&quot;internal/modules/cjs/loader.js&quot;,&quot;lineNumber&quot;:1175,&quot;columnNumber&quot;:9},{&quot;functionName&quot;:&quot;Module.load&quot;,&quot;scriptId&quot;:&quot;44&quot;,&quot;url&quot;:&quot;internal/modules/cjs/loader.js&quot;,&quot;lineNumber&quot;:999,&quot;columnNumber&quot;:31},{&quot;functionName&quot;:&quot;Module._load&quot;,&quot;scriptId&quot;:&quot;44&quot;,&quot;url&quot;:&quot;internal/modules/cjs/loader.js&quot;,&quot;lineNumber&quot;:898,&quot;columnNumber&quot;:13},{&quot;functionName&quot;:&quot;executeUserEntryPoint&quot;,&quot;scriptId&quot;:&quot;53&quot;,&quot;url&quot;:&quot;internal/modules/run_main.js&quot;,&quot;lineNumber&quot;:73,&quot;columnNumber&quot;:11},{&quot;functionName&quot;:&quot;&quot;,&quot;scriptId&quot;:&quot;40&quot;,&quot;url&quot;:&quot;internal/main/run_main_module.js&quot;,&quot;lineNumber&quot;:17,&quot;columnNumber&quot;:46}]}}}"><pre class="notranslate"><code class="notranslate">Client &lt; {"method":"Console.messageAdded","params":{"message":{"source":"console-api","level":"log","text":"Adding  1 2","url":"/home/gudmund/code/ts-test/build/index.js","line":2,"column":13}}}
Client &lt; {"method":"Runtime.consoleAPICalled","params":{"type":"log","args":[{"type":"string","value":"Adding "},{"type":"number","value":1,"description":"1"},{"type":"number","value":2,"description":"2"}],"executionContextId":1,"timestamp":1587836285935.544,"stackTrace":{"callFrames":[{"functionName":"add","scriptId":"54","url":"file:///home/gudmund/code/ts-test/build/index.js","lineNumber":1,"columnNumber":12},{"functionName":"","scriptId":"54","url":"file:///home/gudmund/code/ts-test/build/index.js","lineNumber":7,"columnNumber":15},{"functionName":"Module._compile","scriptId":"44","url":"internal/modules/cjs/loader.js","lineNumber":1152,"columnNumber":13},{"functionName":"Module._extensions..js","scriptId":"44","url":"internal/modules/cjs/loader.js","lineNumber":1175,"columnNumber":9},{"functionName":"Module.load","scriptId":"44","url":"internal/modules/cjs/loader.js","lineNumber":999,"columnNumber":31},{"functionName":"Module._load","scriptId":"44","url":"internal/modules/cjs/loader.js","lineNumber":898,"columnNumber":13},{"functionName":"executeUserEntryPoint","scriptId":"53","url":"internal/modules/run_main.js","lineNumber":73,"columnNumber":11},{"functionName":"","scriptId":"40","url":"internal/main/run_main_module.js","lineNumber":17,"columnNumber":46}]}}}
</code></pre></div>
<p dir="auto">From which one can inspect logged variables via the debugger.<br>
<a href="https://github.com/v8/v8/blob/master/src/inspector/v8-console.cc#L219">https://github.com/v8/v8/blob/master/src/inspector/v8-console.cc#L219</a><br>
This <code class="notranslate">console</code> implementation is available on globalThis.</p>
<p dir="auto">In trying to utilize this, there were two issues:</p>
<ul dir="auto">
<li><strong>Detection of debugger/inspector mode</strong>. If the normal 'console...' calls are to be routed to the v8 implementation in debugger mode, I did not see a way to detect debugger/inspector mode.</li>
<li><strong>Implementation routing of console calls to v8 console</strong>.</li>
</ul>
<p dir="auto">There is a simple example implementation in a PR incoming below, just meant to illustrate.</p>
<h3 dir="auto">Diff between deno's and v8's <code class="notranslate">console</code></h3>
<p dir="auto">A simple name comparison gives the following diff.</p>
<p dir="auto"><strong>v8 extra:</strong></p>
<ul dir="auto">
<li><code class="notranslate">context(name)</code> - <a href="https://umaar.com/dev-tips/153-log-management/" rel="nofollow">Used to group outputs into tabs in devtools</a></li>
<li><code class="notranslate">profile(name?: string)</code> - Profile code. Have not investigated if this works currently</li>
<li><code class="notranslate">profileEnd()</code></li>
<li><code class="notranslate">timeStamp(name?: string)</code> - <a href="https://developer.mozilla.org/en-US/docs/Web/API/Console/timeStamp" rel="nofollow">Adds a labeled mark to be used with <code class="notranslate">Performance</code></a></li>
</ul>
<p dir="auto"><strong>deno extra:</strong></p>
<ul dir="auto">
<li>(<code class="notranslate">indentLevel</code> - internal)</li>
</ul>