Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

351
Views
How to avoid error level message from info file using winston log file?

I am a beginner in Node JS. I am working on winston log file. I am facing an issue with Winston logger (Node JS). When I run the command "npm start" it shows some error level logs in both the error log file and info log file at an initial run. For all other cases, it works fine.

Also, the warning file shows both error and info level messages. In debug file, there also shows both the error and debug messages all the time. What can be the reason for it? How to log messages in the right manner such a way that error messages logs in the error file, info messages in the info file, warning messges in warn file and debug message in debug file. Please refer to the below code.

Code

const { createLogger, transports, format } = require('winston');

const { combine, timestamp, prettyPrint, printf } = format;

const customFormat = printf(({ level, message, timestamp }) => {
    if (!message.includes('&')) {       
        return `${timestamp} ${level}: ${message}`;
    } else {
        return `${timestamp} - ${message.split('&')[0]} - ${level}: ${message.split('&')[1]}`;
    }
});

const logger = createLogger({
    format: combine(
        timestamp(),
        // prettyPrint(),
        customFormat
    ),
    transports: [       
        new transports.File({
            filename: `${__dirname}/log/error.log`,
            level: 'error'
        }),
        new transports.File({
            filename: `${__dirname}/log/info.log`,
            level: 'info'
        }),
        new transports.File({
            filename: `${__dirname}/log/warn.log`,
            level: 'warn'
        }),
        new transports.File({
            filename: `${__dirname}/log/debug.log`,
            level: 'debug'
        }),
        new transports.Console({
            timestamp: true
        }),
    ],
    exceptionHandlers: [
        new transports.Console({
            json: false,
            timestamp: true
        }),
        new transports.File({
            filename: `${__dirname}/log/exceptions.log`,
            json: false
        })
    ],
    exitOnError: false
});

module.exports = logger;


about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!