0

I tired to winston log file in node js.I created sample code using winston log file so,info message stored in info.log file and error message stored in error.log.but my case info message and error message stored in same file .I want separate file. How to achieve it.

winston.js

const winston = require('winston')

const myCustomLevels = {
    levels: {
      info: 0,
      error: 1
    },
    colors: {
      foo: 'blue',
      bar: 'green',
      baz: 'yellow',
      foobar: 'red'
    }
  };

const logger = winston.createLogger({
    transports: [
      new winston.transports.Console({ level: 'error' }),
      new winston.transports.File({
        filename: 'combined.log',
        level: info
      })
    ]
  });
  logger.log('info',"hello")
  logger.error("Hai")

I got output combined.log

{"level":"info","message":"hello"}
{"message":"Hai","level":"error"}

Excepted ouput combined.log

{"level":"info","message":"hello"}
hari prasanth
  • 716
  • 1
  • 15
  • 35
  • 1
    Check out this https://stackoverflow.com/questions/56907439/winston-morgan-logging-avoiding-duplicate-entries – l2ysho Jul 17 '19 at 05:29
  • @l2ysho thanks for your answaer its working fine and one more thing I want handle unhandleexception How to achieve this code. any suggestion – hari prasanth Jul 17 '19 at 05:36
  • You can put your code to try/catch block or use a process.on listener, look at this article to `The unhandledRejection Event` part https://thecodebarbarian.com/unhandled-promise-rejections-in-node.js.html – l2ysho Jul 17 '19 at 08:13

0 Answers0