javascriptconsole.logjavascriptcore

Can i log different TYPES of message in the console?


I skimmed through the MDN documentation of console.log, which indicates there is no extra arguments defining the type of message being logged. Despite this, i see messages in my web browser's Console that are blatantly red, indicating a very important error has occurred.

So i am wondering if this is strictly a browser functionality to indicate glaring red errors? Which would mean that anything written to the console via Javascript will always be plain default looking? Or am i just missing some extra functions for writing more "complex" data to the console?

So, the goal here is for me to be able to write the default looking notifications, such as "service started, everything is ok", then warnings such as "image is missing, but it's fine" that would appear as yellow warnings, and then finally errors such as "could not perform action because server has burnt down" that would appear as a red warning, just like my browser does about "Uncaught DOMExceptions".

Is this possible programmatically (via Javascript)?


Solution

  • // If there are different types of messages in the console.
    // for example:
    
    console.log("my message");
    
    console.error("my error");
    
    console.warn("my warn");
    
    console.info("my info");
    

    Info: https://developer.mozilla.org/es/docs/Web/API/Console