99voices_npm_logger 中文文档教程

发布于 7年前 浏览 32 项目主页 更新于 3年前

Logger

这个包包含一个记录器。 它建立在事实上返回一个实例 温斯顿。 深入概述 这个包返回的对象的api,见文档 温斯顿

Development

这个包是在 docker 容器中开发的。 运行 scripts/build.shscripts/run.sh 获取开发环境。 对于每个纱线操作 执行到容器 docker exec -it ${container_id} /bin/ash 并运行 yarn ... 中的操作。 容器监视文件更改 来源并自动重建分发代码。 在运行 yarn publish 之前 请务必运行 yarn login

Usage

这个包包含并返回一个单例。 这意味着您可以要求 随心所欲地创建文件,您将始终获得相同的日志记录实例。 为了使其工作,首先初始化记录器实例至关重要。 这是一个同步过程,并且是这样完成的:

import Config from '99voices_npm_config';
import Logger from '99voices_npm_logger';

let config = Config();
let Logger = Logger({config});

logWithRequest

这个包将自定义方法 logWithRequest(level,request,message,data) 添加到记录器实例。 这是 在 web 进程中记录日志时很有用。 它接受以下选项:

  • level String - The log level. See winston for more info
  • request Express.request - The request that this log relates to
  • message String - Your message. logWithRequest will reformat the message and add request meta data to it
  • data Object - An object you want to log. See winston for more info

Logger

This package contains a logger. It is build on, and defacto returns an instance of winston. For an in depth Overview of the api of the object returned by this package, see the documentation of winston.

Development

This package is developed within a docker container. Run scripts/build.sh and scripts/run.sh to obtain the development environment. For every yarn operation exec into the container docker exec -it ${container_id} /bin/ash and run the opreation inside yarn .... The container watches for file changes on the sources and automatically rebuilds the distribution code. Before running yarn publish be sure to run yarn login.

Usage

This package contains and returns a singleton. Meaning that you can require the file wherever you want to, and you will always obtain the same logging instance. In order for this to work it is vital that the logger instance is first initialized. This is a synchronous process and done like this:

import Config from '99voices_npm_config';
import Logger from '99voices_npm_logger';

let config = Config();
let Logger = Logger({config});

logWithRequest

This package adds a custom method logWithRequest(level,request,message,data) to the logger instance. It is useful when logging during web processes. It accepts the following options:

  • level String - The log level. See winston for more info
  • request Express.request - The request that this log relates to
  • message String - Your message. logWithRequest will reformat the message and add request meta data to it
  • data Object - An object you want to log. See winston for more info
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文