Winston: How do I use the timestamp format in winston@3? (was: Winston 3 no timestamp in FileTransportOptions)

Created on 4 Jun 2018  Â·  2Comments  Â·  Source: winstonjs/winston

How to enable timestamps in file transports.

This is definition of FileTransportOptions

 interface FileTransportOptions extends Transport.TransportStreamOptions {
    filename?: string;
    dirname?: string;
    options?: object;
    maxsize?: number;
    stream?: NodeJS.WritableStream;
    rotationFormat?: Function;
    zippedArchive?: boolean;
    maxFiles?: number;
    eol?: string;
    tailable?: boolean;
  }

I found only this way:

new winston.transports.File({
        filename: './logs/ttracker.log',
        timestamp: tsFormat,            // makes timestamp 'pretty'
        json: false                 // makes log format just like console output
    })

No timestamp option available in winston 3 looks like it for 2nd version.

Actually pretty hard to do for such essential thing, in most logging frameworks timestamps works from the box.

faq use a custom format

Most helpful comment

Howdy – most options like timestamp and json became formatters in winston@3. A timestamp format is included out of the box in winston.format.timestamp – there is a detailed example in examples/ that shows you how to do use it.

We definitely need help in building out the documentation for built-in formats. If you are interested in becoming a first-time contributor this issue would be a great place to start: https://github.com/winstonjs/logform/issues/9

All 2 comments

Howdy – most options like timestamp and json became formatters in winston@3. A timestamp format is included out of the box in winston.format.timestamp – there is a detailed example in examples/ that shows you how to do use it.

We definitely need help in building out the documentation for built-in formats. If you are interested in becoming a first-time contributor this issue would be a great place to start: https://github.com/winstonjs/logform/issues/9

How do you add a custom format that is not based on that library?
I still prefer to use moment not fecha

Was this page helpful?
0 / 5 - 0 ratings