node.jsbunyan

how do I filter a bunyan log based on date?


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?


Solution

  • 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")'