解释Winston记录器中级别的使用 [英] Explain use of levels in winston logger

查看:59
本文介绍了解释Winston记录器中级别的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在使用此Winston记录器,请解释一下传输器内部级别的使用,如果我在记录时将logger与信息一起使用会发生什么,在记录数据时是否必须使用debug.

Hey i am using this winston logger, kindly explain use of level inside the transports, what will happen if i use logger with info while logging, do i have to use debug while i log my data.

var logger = new (winston.Logger)({
transports: [
  new (winston.transports.Console)({
    level: 'debug',
    json: true
  }),
  new (winston.transports.File)({
    name: 'order_check',
    filename: './logs/order_check.log',
    level: 'debug'
  })
]
});
logger.log("info","request body");

推荐答案

传输中的级别指示传输将侦听"的最小日志记录级别.

The level inside your transport indiciates the minimum logging level that transport will "listen out for"

从文档中: https://github.com/winstonjs/winston#logging-levels

每个级别都有特定的整数优先级.优先级越高,则认为该消息越重要

Each level is given a specific integer priority. The higher the priority the more important the message is considered to be

{ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }

因此,在您的示例中,您将传输配置为 debug:4

So, in your example, you're transports are configured for debug: 4

这意味着它将记录级别

  • 4(调试)
  • 3(详细)
  • 2(信息)
  • 1(警告)
  • 0(错误)

一个好的用例是将一种传输方式(例如控制台)设置为调试方式,将另一种传输方式设置为信息方式.

A good use case for this would be to set one transport (Console for example) to debug, and your other to info.

这会将所有 debug 信息输出到控制台,但仅将 info 记录到文件中,从而防止日志文件混乱.

This would output all debug information to the console, but only log info to file, preventing log file clutter.

这篇关于解释Winston记录器中级别的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆