简体   繁体   English

将控制台传输附加到Winston日志记录

[英]Attaching console transport to Winston logging

So I'm trying to attach console as a transport to winston logger. 所以我试图将控制台作为传输附加到winston记录器。 Below is my code. 以下是我的代码。

winston.add(winston.transports.Console, {
    level: 'info',
    colorize: true,
    timestamp: true,
    json: false,
    stringify: false,
    prettyPrint: true,
    depth: 5,
    humanReadableUnhandledException: true,
    showLevel: true,
    stderrLevels: ['error', 'debug']
});

But when I start the application,I get below error. 但是,当我启动应用程序时,我得到以下错误。

C:\Users\xxxxx\yyyyy\javascript\MyApp\node_modules\winston\lib\winston\logger.js:481
    throw new Error('Transport already attached: ' + instance.name + ", assign a different name");
    ^

Error: Transport already attached: console, assign a different name
    at Logger.add (C:\Users\xxxxx\yyyyy\javascript\MyApp\node_modules\winston\lib\winston\logger.js:481:11)
    at Object.winston.(anonymous function) [as add] (C:\Users\xxxxx\yyyyy\javascript\MyApp\node_modules\winston\lib\winston.js:87:34)
    at Object.<anonymous> (C:\Users\xxxxx\yyyyy\javascript\MyApp\app.js:36:9)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\Users\xxxxx\yyyyy\javascript\MyApp\bin\www:7:11)

Now, I understand that my console is already by default attached to the logger. 现在,我知道我的控制台已默认附加到记录器。 But I am writing this additionally because I want to change the configurations according to my preferences. 但我还在写这个,因为我想根据自己的喜好改变配置。

Can anyone suggest how do I achieve this? 任何人都可以建议我如何实现这一目标? Do I have to put some other syntax in order to change configuration of already attached transport or is there any way around this with the same code I am using? 我是否必须使用其他语法来更改已连接的传输的配置,或者使用与我使用的相同代码有什么方法吗?

Please suggest. 请建议。

If you already have a transport of the same type attached, you need to name the new transport: 如果您已经连接了相同类型的传输,则需要为新传输命名:

winston.add(winston.transports.Console, {
  name : 'UNIQUE_NAME_HERE',
  level: 'info',
  ...
});

Documented here . 记录在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM