hapijs / good

hapi process monitoring
Other
525 stars 161 forks source link

Is there a way to change the timestamp format to ISO? #577

Closed frankthelen closed 6 years ago

frankthelen commented 6 years ago

Hi!

I have a question (can't find anything it the docs): Is there a way to change the timestamp date format to ISO.

I am using this reporter configuration with Good 8.0.0-rc1.

    reporters: {
      stdout: [{
        module: 'good-squeeze',
        name: 'Squeeze',
        args: [{
          log: '*', request: '*', response: '*', error: '*'
        }],
      }, {
        module: 'white-out',
        args: [{
          password: 'censor'
        }]
      }, {
        module: 'good-squeeze',
        name: 'SafeJson',
      }, 'stdout'],
    },

Which outputs timestamp in milliseconds like this:

{"event":"log","timestamp":1515606782890,"tags":["info"],"data":...,"pid":89579}

Thanks.

arb commented 6 years ago

Check the good-console docs. That's what formats the timestamp before sending it to 'stdout'.

frankthelen commented 6 years ago

Thanks for your quick answer. If I understand correctly, good-console doesn't play together with good-squeeze/SafeJson, right. So, if I want to have a JSON-formatted log output with its timestamp ISO-formatted, it doesn't seam to work. Or am I doing something wrong. Thanks.

arb commented 6 years ago

Sorry, I misread your configuration! You aren't using good-console.

The reporting pipeline you have configured will just take the values from the "log", "request", "response" and "error" events, censor out "password" if it's there, JSONify it and then pipe it to stdout.

If you want to do some additional formatting, you'll need to have some kind of transformation stream in there to morph the timestamp to a different format. Probably after "white-out" and before "SafeJson" as the log values are still objects at that point in the pipeline.

frankthelen commented 6 years ago

Yep. Unfortunately, I didn't find a package that works for me. Anyway, I decided to have some fun and write my own transform stream. Maybe it's also interesting for others. Here it is: https://www.npmjs.com/package/good-map

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.