Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging only the message using winston

I am using winston logger in my node app and i want to log my custom message to the log file.

var logger = new winston.Logger({
    transports: [
        new winston.transports.File({
            level: 'info',
            filename: '/tmp/test.log',
            handleExceptions: true,
            json: true,
            maxsize: 20971520 //20MB
        })
    ],
    exitOnError: false
});

I only need to log message in the log, i dont need to log level and timestamp in the log file. Current logged sample is as below.

{"level":"info","message":"sample entry to log","timestamp":"2015-12-11T09:43:50.507Z"}

My intention is to get entry in the log file as below

sample entry to log

How to achieve this?

like image 799
Share_Improve Avatar asked Mar 19 '26 01:03

Share_Improve


1 Answers

Winston 3:

import winston from 'winston';

const logger = winston.createLogger({
  level: 'info',
  transports: [
    new winston.transports.Console({
      format: winston.format.printf(log => log.message),
    })
  ]
});

logger.info('eat my shorts');
like image 90
mrcrowl Avatar answered Mar 21 '26 15:03

mrcrowl