Node.js console.log vs console.info

后端 未结 10 1177
青春惊慌失措
青春惊慌失措 2021-01-30 15:51

What is the benefit of using console.log vs console.info? Or any of the other console commands for that matter?

console.info(\"info\")         


        
相关标签:
10条回答
  • 2021-01-30 16:11

    The different logging levels let you manage the noise level in your console: In both the Firefox (I'm using 78 right now) and Chrome (84) devtools, the js console lets you choose what "debug level" of output you want to see. FF lets you toggle the visibility of console.error, .warn, .log, .info, and .debug messages by clicking individual buttons for each (that show you how many were suppressed, when "off"), whereas Chrome has a dropdown with checkmarks next to the items (.info and .log are controlled by the "Info" one, and .debug by "Verbose"). The Chrome dropdown label ("All levels" or whatever you set) turns red if output was suppressed.

    0 讨论(0)
  • 2021-01-30 16:17

    While console.log and console.info might not be different, there are other uses except mere coloring. For example, when using a linter like eslint, you can set console.log to provide a warning message. Let's say you only want to use console.log for your development purposes and use console.info for information that end users might need. With a linter you now have a visible and direct reminder of your temporary console.log that aid you during development, but must be removed before commits/publishing.

    0 讨论(0)
  • 2021-01-30 16:21

    console.log() is shorter than console.info()

    They're the same thing, and that's the only advantage.

    0 讨论(0)
  • 2021-01-30 16:21

    Visually, No difference actually among console.log , console.info , console.warn , as well as console.error regarding the server side(terminal).

    However, there are lightweight modules that add blue, orange and red colors for console.info , console.warn , as well as console.error respectively . By that, console API behaves like client-side.

     npm i console-info console-warn console-error --save-dev;
    

    0 讨论(0)
提交回复
热议问题