Home > Back-end >  Is it possible to separate outputs on different consoles in browsers?
Is it possible to separate outputs on different consoles in browsers?

Time:10-29

I've searched but can't find anything. Maybe I am using the wrong words.

I am currently working on an application that launches numerous messages of all kinds to the console in real time for monitoring and debugging purposes. On the desktop in some languages ​​it is easy to separate into different consoles or even into different log files, but in browsers I have to filter continuously.

Is it possible to have different output streams in some way in browsers (Firefox or Chrome)? Is there even a way to have more than one console, console tabs...?

CodePudding user response:

There is only one console, so you can't split it up into multiple streams that would be analogous to what you can do with desktop apps.

One thing you could potentially do is (ab)use the different levels of output:

  • console.debug() => Verbose
  • console.info() => Info
  • console.warn() => Warning
  • console.error() => Error

While not separate streams, browsers do let you filter on the different levels, so this could effectively give you four filterable "streams" to see different sets of data.


Or, as Pointy mentioned, you could also color (or even style) your output, either using %c:

console.log('%c Hello World', 'color:#0F0;border:1px solid #F00');

Or using escape sequences like in terminals:

console.log('\x1b[33m%s\x1b[0m', 'hi!');

Though there wouldn't be a way to filter on those.


One final option would be to start each "stream" with a different keyword and then simply filter on those keywords:

console.log('[User] Bob logged in.');
console.log('[HTTP] Request sent.');
console.log('[Repo] Data acquired.');

I'd personally probably use that last one.

  • Related