如何根据日期过滤 bunyan 日志?
how do I filter a bunyan log based on date?
获得了 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 年没有任何作用。
那么我在日期过滤方面做错了什么?
答案似乎是在调用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 命令行实现。
JSON中的时间存储为字符串。所以比较之前需要先转换一下。
bunyan /opt/aaa/.pm2/logs/cccc-out-15.log -c 'new Date(this.time) >= new Date("2016-05-31T15:38:47.889Z")'
获得了 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 年没有任何作用。
那么我在日期过滤方面做错了什么?
答案似乎是在调用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 命令行实现。
JSON中的时间存储为字符串。所以比较之前需要先转换一下。
bunyan /opt/aaa/.pm2/logs/cccc-out-15.log -c 'new Date(this.time) >= new Date("2016-05-31T15:38:47.889Z")'