admin管理员组文章数量:1327301
So I'm trying to attach console as a transport to winston logger. 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._pile (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.
So I'm trying to attach console as a transport to winston logger. 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._pile (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.
Share Improve this question asked Sep 22, 2016 at 9:10 Keyur GolaniKeyur Golani 5838 silver badges26 bronze badges1 Answer
Reset to default 8If 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.
本文标签: javascriptAttaching console transport to Winston loggingStack Overflow
版权声明:本文标题:javascript - Attaching console transport to Winston logging - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742205587a2432753.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论