question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

3.0.0-rc1 - Unable to log timestamps

See original GitHub issue

I followed the example from the documentation, and created a logger as shown below:

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

const logger = createLogger(
    {
        level: 'info',
        transports: [new transports.Console({
            showLevel: false,
            colorize: true,
            timestamp: true
        })
        ]
    }
);

logger.info('Server started');

But, I can seem to get the time stamps working. I get the following output in black and white:

{“message”:“Server started”,“level”:“info”}

Based on the documentation at https://github.com/winstonjs/winston/blob/master/docs/transports.md#console-transport, setting timestamp flag to true should put a default timestamp.

I even tried by returning a custom timestamp by passing a function but even that doesn’t show up. Perhaps, I missed something but it seems like none of the options work, ie. colorize, showLevel, timestamp.

Or is the documentation out of sync?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

32reactions
ChrisAldersoncommented, Feb 21, 2018

@armadillojim

Use the printf format like this:

const { createLogger, format, transports } = require('winston')
const { colorize, combine, timestamp, printf } = format

// Define your custom format with printf.
const myFormat = printf(info => {
  return `${info.timestamp} ${info.level}: ${info.message}`
})

const logger = createLogger({
  format: combine(
    timestamp(),
    colorize(),
    myFormat
  ),
  transports: [new transports.Console()]
})

logger.info('foo') // -> 2018-02-21T03:55:19.236Z info: foo
12reactions
justLuizcommented, Jan 25, 2018

why format.timestamp does not work without format.json being declared after format.timestamp?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - How to add timestamp to logs using Winston library?
In case you are trying to add timestamp to your logs using the latest version of Winston - 3.0.0-rc1, ... There are two...
Read more >
How do I resolve the error "Bad request timestamp" when ...
Log in to the Duo Admin Panel and see if you can find the failed authentication attempt in the Authentication Logs. If you...
Read more >
Release Notes for Zabbix 3.0.0rc1
This document contains the release notes for Zabbix 3.0.0rc1. ... ZBX-10102, Added support for log file meta information update for items ...
Read more >
Version history - FileZilla
SFTP: Fixed error handling if reading from child process fails ... MSW: Toggling the log timestamp option no longer results in wrong log...
Read more >
PutLogEvents - Amazon CloudWatch Logs
Uploads a batch of log events to the specified log stream. ... The log events in the batch must be in chronological order...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found