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

Problems with timestamps #139

Open
mlasevich opened this issue Apr 24, 2020 · 2 comments · May be fixed by #157
Open

Problems with timestamps #139

mlasevich opened this issue Apr 24, 2020 · 2 comments · May be fixed by #157

Comments

@mlasevich
Copy link

Running into trouble with generated timestamps in both protocols

Under BSD it generates a timestamp using local time without timezone. While this may actually be to spec, it does not produce expected result. Would be nice to have option to force time to be UTC

Under 5424 format things look much worse. I am seeing BOTH UTC time AND local timezone

So the generated timestamp looks like this: 2020-04-23T02:54:14.364-07:00 when "02:54:14.364" is the UTC time, not local (-7) time - so combination of both makes wrong time

Very strange and I am surprised I am the only one to notice.

example code:

const winston = require('winston');
require('winston-syslog').Syslog;

const logger = winston.createLogger({
  transports: [
    new winston.transports.Syslog({
        type: "5424",
        app_name: "myapp",
        host: "localhost",
})
  ]
});

logger.info('What rolls down stairs');

this produces line:
<134>1 2020-04-24T03:25:12.980-07:00 localhost myapp 57665 - - {"message":"What rolls down stairs","level":"info"}

when local time is Thu Apr 23 20:25:12 PDT 2020

@mlasevich
Copy link
Author

Upon digging, this seems to be a bug in glossy

@bmaupin
Copy link

bmaupin commented Sep 27, 2021

Interestingly enough, I think that bug may have already been fixed back in 2016 (squeeks/glossy#34), but glossy hasn't had any new releases since 2014.

There's actually a second bug which only occurs when milliseconds are less than 100:

<131>1 2021-09-27T15:52:34.137-07:00 localhost test-graylog-syslog 103039 - - error: Test error message, without stack trace
<131>1 2021-09-27T15:52:35.35-07:00 localhost test-graylog-syslog 103065 - - error: Test error message, without stack trace

15:52:35.35 should be 15:52:35.035. Unfortunately Graylog interprets it as 15:52:35.350.

This library doesn't seem to be well-maintained, but there is a way to work around both of these 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,
          // ...

I have a more fully-fledged example app here in case it's helpful: https://github.com/bmaupin/graylog-syslog-examples/tree/main/winston

bmaupin added a commit to bmaupin/graylog-syslog-examples that referenced this issue Sep 28, 2021
bmaupin added a commit to bmaupin/winston-syslog that referenced this issue Sep 30, 2021
- Use the correct time zone (fixes winstonjs#139)
- Fix formatting for milliseconds (fixes winstonjs#156)
- Add tests
@bmaupin bmaupin linked a pull request Sep 30, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants