Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are milliseconds supported? #133

Open
mhterres opened this issue Feb 27, 2020 · 1 comment
Open

Are milliseconds supported? #133

mhterres opened this issue Feb 27, 2020 · 1 comment

Comments

@mhterres
Copy link

Hello.

I'm using winston-syslog to send logs to a Graylog server and I noticed that all entries on the Graylog server are missing the milliseconds information.

Is it expected or am I doing something wrong?

Thanks.

@bmaupin
Copy link

bmaupin commented Sep 28, 2021

By default, this library will send logs using the BSD (RFC 3164) format, which doesn't include milliseconds. You can use the better RFC 5424 format (which includes milliseconds) by setting type: '5424' in the transport options, e.g.

new winston.transports.Syslog({
  type: '5424',

Unfortunately, this library uses another library called glossy to do the actual formatting, and glossy suffers from a couple different bugs related to the timestamp (#139).

Here's how I was able to work around those bugs:

  1. Install a newer fork of glossy

    npm install @myndzi/glossy
    
  2. Import the fork of glossy

    const glossy = require('@myndzi/glossy');
  3. Pass the producer from the fork of glossy into the syslog transport via customProducer:

    const logger = winston.createLogger({
    transports: [
       new winston.transports.Syslog({
          customProducer: glossy.Produce,
          // ...

In my testing, those changes were enough for the logs to show in Graylog with proper timestamps. I have a small example project here you might find helpful: https://github.com/bmaupin/graylog-syslog-examples/tree/main/winston

I also have other examples for Pino and Bunyan. Pino is probably the most promising of the three although not quite ready for production as of the time of this writing.

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants