Winston: How do you disable JSON logging for files? (v3)

Created on 17 Apr 2018  路  2Comments  路  Source: winstonjs/winston

I cannot figure out how to disable JSON logging to a file. I want plain date: string logging.

  // https://github.com/winstonjs/winston/blob/master/docs/transports.md#file-transport
  logger = createLogger({
    level,
    json: false,
    // format: [
    //   format.timestamp(),
    //   // format.printf(i => `${i.timestamp}: ${i.message}`),
    // ],
    transports: [new transports.File({ filename: 'query.log', json: false })],
  });

Most helpful comment

This is the answer you are looking for:

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

const logger = createLogger({
  format: format.combine(
    format.timestamp(),
    format.printf(i => `${i.timestamp} | ${i.message}`)
  ),
  transports: [
    new transports.Stream({
      stream: fs.createWriteStream(path.join(__dirname, 'example.log'))
    })
  ]
})

logger.log({
  level: 'info',
  message: 'Check example.log 鈥撀爄t will have no colors!'
});

All 2 comments

This is the answer you are looking for:

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

const logger = createLogger({
  format: format.combine(
    format.timestamp(),
    format.printf(i => `${i.timestamp} | ${i.message}`)
  ),
  transports: [
    new transports.Stream({
      stream: fs.createWriteStream(path.join(__dirname, 'example.log'))
    })
  ]
})

logger.log({
  level: 'info',
  message: 'Check example.log 鈥撀爄t will have no colors!'
});

We should have this in the example

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alditis picture alditis  路  3Comments

pocesar picture pocesar  路  3Comments

KingRial picture KingRial  路  3Comments

mohanen picture mohanen  路  4Comments

ghost picture ghost  路  4Comments