1

I tried to install the latest winston version in node.js but it does not create log file. but the old version created log file. How to achieve this functionality in latest version code?

winston.js

/**
 * @fileoverview Winston Logging Configuration file.
 */

// Import Modules
const winston = require('winston');
require('winston-mongodb');
require('express-async-errors');

/**
 * Function used to configure logging for the app.
 * @param {Function} app - top-level function Express funtion.
 * @returns {void} - none.
 */
const winstonLogging = function () {
    // Uncaught Exceptions and UnchandledRejections 
    winston.handleExceptions(
        new winston.transports.Console({ colorize: true, prettyPrint: true }),
        new winston.transports.File({ filename: 'uncaughtExceptions.log' }));
    process.on('unhandledRejection', (ex) => {
        throw ex;
    });

    // Winston Configuration
    winston.add(new winston.transports.File({ filename: 'logfile.log' }));
    winston.add(new winston.transports.MongoDB({
        db: 'mongodb://olcadmin:olcmongodb@127.0.0.1:27017/local?authMechanism=SCRAM-SHA-1&authSource=admin',
        level: 'info'
    }));
}

module.exports = winstonLogging;

old version

"winston": "^2.4.0"  
Its working fine and sucessfully created log file

new version

"winston": "^3.2.1"  
Its not created log file  

I facing Error

[winston] Attempt to write logs with no transports {"message":"Server Started and Listening on port 5200","level":"info"} 
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
hari prasanth
  • 716
  • 1
  • 15
  • 35
  • Possible duplicate of [Winston: Attempt to write logs with no transports](https://stackoverflow.com/questions/49271570/winston-attempt-to-write-logs-with-no-transports) – Dez Jun 28 '19 at 09:00
  • In a v3.2.1 you have to create transports in a different way, check the official docs – l2ysho Jul 05 '19 at 20:13

0 Answers0