1

有一个 bunyan 日志,这是一个示例条目

[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
    }

好的,我想找到那个之后的所有条目:

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

没结果。也试过了this.time。bunyan 文档说这time是正确的字段,但它不起作用。new Date("2016-05-31T15:38:47.889Z")'已验证:

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

日志过滤肯定有效:

$ 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

将年份更改为 2015 年并没有做任何事情。

那么我在日期过滤方面做错了什么?

4

2 回答 2

2

JSON 中的时间存储为字符串。因此,您需要在比较之前对其进行转换。

bunyan /opt/aaa/.pm2/logs/cccc-out-15.log -c 'new Date(this.time) >= new Date("2016-05-31T15:38:47.889Z")'
于 2018-01-06T07:47:07.897 回答
1

答案似乎是在调用 bunyan 之前进行过滤:

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

产生:

[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

为我工作。似乎它应该可以使用 bunyan 命令行。

于 2016-11-21T18:24:01.880 回答