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.

Log messages written in order?

See original GitHub issue

Is it possible to have winston log its messages to a transport in order? It’s hard to read log files that aren’t sequential.

For example, I have a log output that included a date/time with milliseconds. (See below)

Is there a way to specify that each of the log messages be written in the order they occur? Thanks.

2016-02-25 21:34:07.671 INFO  ...
2016-02-25 21:34:07.692 INFO  ...
2016-02-25 21:34:07.690 DEBUG  ...
2016-02-25 21:34:07.692 INFO  ...
2016-02-25 21:34:07.691 DEBUG  ...
2016-02-25 21:34:07.692 DEBUG  ...
2016-02-25 21:34:07.692 DEBUG  ...

NB: The code that generates the timestamps is at: https://github.com/winstonjs/winston/issues/802

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

8reactions
zamnutscommented, Sep 14, 2016

@richb-hanover This is an issue with the default logging levels and their relationship with stdout and stderr. The culprit is: https://github.com/winstonjs/winston/blob/2.2.0/lib/winston/transports/console.js#L118-L122 and the associated option is declared at: https://github.com/winstonjs/winston/blob/2.2.0/lib/winston/transports/console.js#L34

The default stderr log levels are error and debug (defined as ['error','debug']), all other levels are routed to stdout. On the console, stdout and stderr are consolidated in the viewed output; these are separate output streams hence why they appear out of order from a timestamp perspective (think “async”). Obviously, if you’re sending stderr and stdout to separate files this quirk will not be apparent; again, it only surfaces when the streams are consolidated.

As a work-around, you could set your Console transport’s stderrLevels option to an empty array which tells it to not log anything to stderr, and only to stdout. However, the side-effect to the work-around is that you can no longer distinguish between error and non-error output at the stream level. Be cautious to where you employ this.

For example, when defining the console transport:

new winston.transports.Console({stderrLevels:[]});

IMO, this is not a bug.

0reactions
OndroNRcommented, Nov 3, 2017

@zamnuts’s answer should be mentioned in readme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is chronological order of logging messages guaranteed?
Even then, log messages from the same thread will never be written out in a different order, they'll just be intermixed with messages...
Read more >
Logging Best Practices: The 13 You Should Know - DataSet
Just as log messages can be written for different audiences, log messages can be used for different reasons. Even though troubleshooting is ...
Read more >
1120894 – syslog messages very badly out of order in /var/log ...
rsyslog writes messages in the order it receives them and therefore can't enforce chronological order. With flat text files, there's not much ...
Read more >
Messages "out of order segment" in /var/log/messages | Support
They are debugging messages from the IPv4 TCP/IP stack that indicate a data segment was received out of order (based on sequence number),...
Read more >
Weird syslog order - ubuntu - Server Fault
It looks like the other logs except cron are OK. I added logging time by "something" script, not just cron and syslog. –...
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