gpt4 book ai didi

node.js - 如何根据日期过滤 Bunyan 日志?

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:46 24 4
gpt4 key购买 nike

有一个 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 年没有任何作用。

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

最佳答案

JSON 中的时间存储为字符串。所以比较之前需要先转换一下。

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

关于node.js - 如何根据日期过滤 Bunyan 日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37977450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com