1

Got a bunyan log, here's a sample entry

[2016-05-31T15:38:47.889Z] FATAL: jklajsd-utilities/23399 on aaa.bbb.ccc.com: 
    0: {
      "code": "EADDRINUSE",
      "errno": "EADDRINUSE",
      "syscall": "listen",
      "address": "0.0.0.0",
      "port": 5566
    }

OK I want to find all entries after that one:

bunyan /opt/aaa/.pm2/logs/cccc-out-15.log -c 'this.date >= new Date("2016-05-31T15:38:47.889Z")' 

No results. Tried with this.time as well. The bunyan docs say that time is the right field but it doesn't work. new Date("2016-05-31T15:38:47.889Z")' is valid:

> new Date("2016-05-31T15:58:50.475Z")
Tue May 31 2016 08:58:50 GMT-0700 (PDT)

The log filtering is certainly working:

$ bunyan /opt/aaa/.pm2/logs/cccc-out-15.log -c 'this.level === DEBUG ' |wc -l 
102455

$ bunyan /opt/aaa/.pm2/logs/cccc-out-15.log -c 'this.level === FATAL '|wc -l 
1679

Changing the year to 2015 didn't do anything.

So what am I doing wrong with date filtering?

jcollum
  • 43,623
  • 55
  • 191
  • 321

2 Answers2

2

The time in JSON is stored as a string. So you need to convert it before comparing.

bunyan /opt/aaa/.pm2/logs/cccc-out-15.log -c 'new Date(this.time) >= new Date("2016-05-31T15:38:47.889Z")'
A.N
  • 46
  • 4
  • This is the correct answer. Filtering with `grep` prior to `bunyan`(as the other answer suggests) is just a workaround, but this is the proper way. – maganap Nov 22 '18 at 11:51
1

The answer seems to be to filter before calling bunyan:

cat /opt/xyz/.pm2/logs/whiskey-tango-out-15.log | grep "2016-10-11" | bunyan -o short

Which produces:

[2016-10-11T22:33:08.836Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 3
[2016-10-11T22:33:08.837Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 2
[2016-10-11T22:33:08.837Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 1
[2016-10-11T22:33:08.838Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 3
[2016-10-11T22:33:08.838Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 2
[2016-10-11T22:33:08.838Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 2
[2016-10-11T22:33:08.839Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 6
[2016-10-11T22:33:08.839Z]  WARN: whiskey-tango/8828 on [redacted]: Post failed, retrying, count: 3

Works for me. Seems like it should be doable with the bunyan command line though.

jcollum
  • 43,623
  • 55
  • 191
  • 321