Search code examples
node.jsloggingwinston

In Winston logging module,why that sending logs with different level is not working


In my node application i'm using winston module to store my application logs.I have tried to store the logs in different level and also in different files.In this situation i'm getting error as "Error: Transport already attached: file".

My Code

  var winston=require('winston');
  winston.add(winston.transports.File, { filename: './logfile.log',level:'error' });
  winston.add(winston.transports.File, { filename: './logfile1.log',level:'warn' });
  winston.add(winston.transports.File, { filename: './logfile2.log',level:'debug'});

  winston.log('error', 'Error message!');//this should go to logfile.log
  winston.log('warn', 'Warning message!');//this should go to logfile1.log
  winston.log('debug', 'Debug message!');//this should go to logfile2.log

Solution

  • The winston just support one file transfer in a instance ,you can make more instance to handle the difference level log.