Node.js console.log - Is it possible to update a line rather than create a new line?

后端 未结 6 2083
Happy的楠姐
Happy的楠姐 2020-12-07 12:16

My node.js application has a lot of console logs, which are important for me to see (it\'s quite a big app so runs for a long time and I need to know that thing

6条回答
  •  天涯浪人
    2020-12-07 13:01

    To write a partial line.

    process.stdout.write("text");
    process.stdout.write("more");
    process.stdout.write("\n"); // end the line
    

    If the volume of output is the real issue then you'll probably to rethink your logging. You could use a logging system that allows selective runtime logging to narrow your output to what you need.

    // The sections we want to log and the minimum level
    var LOG_LEVEL = 4;
    var LOG_SECTIONS = ["section1","section2","section3"];
    
    function logit(msg, section, level) {
      if (LOG_SECTIONS.indexOf(section) > -1 && LOG_LEVEL >= level) {
        console.log(section + ":" + msg);
      }
    }
    
    logit("message 1", "section1", 4); // will log
    logit("message 2", "section2", 4); // will log
    logit("message 3", "section3", 2); // wont log, below log level
    logit("message 4", "section4", 4); // wont log, not in a log section
    

提交回复
热议问题