I want to setup logs for my nodejs
project inside a directory named logs
as per documentation here
i am doing :
winston.add(winston.transports.File, { filename: 'logs/mylogs.log' });
But it is doing nothing.
How do i achieve the same?
Put the below code in your server file.
var winston = require('winston');
var fs = require( 'fs' );
var path = require('path');
var logDir = 'log'; // directory path you want to set
if ( !fs.existsSync( logDir ) ) {
// Create the directory if it does not exist
fs.mkdirSync( logDir );
}
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
colorize: 'all'
}),
new (winston.transports.File)({filename: path.join(logDir, '/log.txt')})
]
});
logger.info("Anything you want to write in logfile");