Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  52] [ 6]  / answers: 1 / hits: 28216  / 6 Years ago, sat, august 25, 2018, 12:00:00

I followed a tutorial to set up winston (2.x) default logger in my express app. When updating to the current version of winston (3.0.0) I have a problem with adding the transports. I have followed the latest docs but still I get the notice in console and no log files are created at all:




[winston] Attempt to write logs with no transports




logging.js



const winston = require('winston');

module.exports = function () {

const files = new winston.transports.File({ filename: 'logfile.log' });
const myconsole = new winston.transports.Console();

winston.add(myconsole);
winston.add(files);

}


index.js



const winston = require('winston');
...

require('./logging');
winston.info(Give some info);



[winston] Attempt to write logs with no transports
{message:Give some info,level:info}




What am I doing wrong?


More From » node.js

 Answers
24

I also had a similar issue. If I recall correctly, I had to call the requirement as a function in my index.js.



require('./logging')();

[#53652] Tuesday, August 21, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nestorjarettg

Total Points: 451
Total Questions: 108
Total Answers: 108

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;