如何使用log4js

时间:2017-06-20 06:03:46

标签: javascript typescript protractor log4js-node

我想记录控制台日志,无论是期望失败还是任何异常进入日志文件。如果不使用try和catch,我该怎么做呢? 在LOG4j for java中,有rootlogger可以自动将所有系统信息日志记录到文件中。对于javascript的log4JS也可以这样做

log4js.configure({
  appenders: [
    {
      type: "clustered",
      appenders: [
        {
          type: "dateFile",
          filename: "log/access.log",
          pattern: "-yyyy-MM-dd",
          category: "http"
        },
        {
          type: "file",
          filename: "log/app.log",
          maxLogSize: 10485760,
          numBackups: 3
        },
        {
          type: "logLevelFilter",
          level: "ERROR",
          appender: {
            type: "file",
            filename: "log/errors.log"
          }
        }
      ]
    }
  ]
})

1 个答案:

答案 0 :(得分:2)

您可以覆盖默认的 <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="https://en.wikipedia.org/wiki/International_Organization_for_Standardization" target="_blank"><img src="https://iso.torza.nl/images/iso-logo.png" height="30"></a> </div> 功能,以指向您的记录器,例如

console.log

你可以为其他功能做类似的事情,例如const logger = log4js.getLogger('cheese'); console.log = (msg) => logger.trace(msg); 等。

那就是说。你最好明确地调用console.debug