@addesign/wwt-logger 中文文档教程

发布于 4年前 浏览 6 更新于 3年前

WWT Logger

创建记录器模块是为了记录特定信息。 模板如下所示:

示例:    ERROR [2020 年 11 月 19 日星期四 19:14:58 GMT]:数据库连接出现问题

An example of using the logger:

const path = require("path");
const Logger = require("@addesign/wwt-logger)

const logger_instance = new Logger({ dir: path.join(__dirname, "logs") });
const {logType} = logger_instance

为了向日志文件添加条目,请使用以下代码:

logger_instance.set(logeType.ERROR, `something text for log file`, (err) => { callback })

要获取文件,只需使用 get 方法,我们可以使用内置类型:

const {logType} = logger_instance
logger_instance.get(logType.ERROR, (err, data) => { callback })

An example of using a logger to write all logs to one file:

const path = require("path");
const Logger = require("@addesign/wwt-logger")
const loggerConfig = { 
    dir: path.join(__dirname, "your directory"),
    singleFile: true, 
    singleFileName: "logsFileExample"
}

const instanceLogger = new Logger(loggerConfig)

如果指定了 singleFile,则必须指定 singleFileName。 LoggerConfig 中的 singleFileName 属性不得在文件名末尾包含 ".log"

An example of using the logger with Express.js:

const path = require("path");
const ExpressLogger = require("@addesign/wwt-logger/express")
...
const loggerConfig = { dir: path.join(__dirname, "your directory") }

app
  .use(ExpressLogger(loggerConfig))
  .use((req) => {
    req.logger.logType // log types
    req.logger.get(...)
    req.logger.set(...)
  });

所有记录器类型:

enum LogTypes {
  ERROR = "ERROR",
  INFO = "INFO",
  WARNING = "WARNING",
  DEBUG = "DEBUG",
  FATAL = "FATAL"
}

Licence

版权所有 (c) 2020 AD design ©

特此免费向任何获得副本的人授予许可 本软件和相关文档文件(“软件”),处理 在软件中不受限制,包括但不限于权利 使用、复制、修改、合并、发布、分发、再许可和/或出售 该软件的副本,并允许该软件是 提供这样做,但须满足以下条件:

上述版权声明和本许可声明应包含在所有 软件的副本或重要部分。

软件“按原样”提供,不提供任何形式的明示或保证 暗示的,包括但不限于适销性保证, 适用于特定目的和非侵权。 在任何情况下都不得 作者或版权持有人对任何索赔、损害或其他 责任,无论是在合同、侵权或其他方面的行为中,由以下原因引起, 出于或与软件或使用或其他交易有关 软件。

WWT Logger

The logger module was created in order to log specific information. The template looks like this:

Example:    ERROR [Thu, 19 Nov 2020 19:14:58 GMT]: Something went wrong with the database connection

An example of using the logger:

const path = require("path");
const Logger = require("@addesign/wwt-logger)

const logger_instance = new Logger({ dir: path.join(__dirname, "logs") });
const {logType} = logger_instance

In order to add an entry to the log file, use the following code:

logger_instance.set(logeType.ERROR, `something text for log file`, (err) => { callback })

To get the file, just use the get method and we can use the built-in types:

const {logType} = logger_instance
logger_instance.get(logType.ERROR, (err, data) => { callback })

An example of using a logger to write all logs to one file:

const path = require("path");
const Logger = require("@addesign/wwt-logger")
const loggerConfig = { 
    dir: path.join(__dirname, "your directory"),
    singleFile: true, 
    singleFileName: "logsFileExample"
}

const instanceLogger = new Logger(loggerConfig)

If singleFile is specified, then singleFileName must be specified. The singleFileName property in the LoggerConfig must not contain ".log" at the end of the file name.

An example of using the logger with Express.js:

const path = require("path");
const ExpressLogger = require("@addesign/wwt-logger/express")
...
const loggerConfig = { dir: path.join(__dirname, "your directory") }

app
  .use(ExpressLogger(loggerConfig))
  .use((req) => {
    req.logger.logType // log types
    req.logger.get(...)
    req.logger.set(...)
  });

All logger types:

enum LogTypes {
  ERROR = "ERROR",
  INFO = "INFO",
  WARNING = "WARNING",
  DEBUG = "DEBUG",
  FATAL = "FATAL"
}

Licence

Copyright (c) 2020 AD design ©

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文