将日志文件解析到JSON对象
这是日志文件的内容
[2022-06-30T09:56:40.146Z] ### POST https://test.csdf/auth/send_otp
{
"method": "POST",
"headers": {
"User-Agent": "testing",
"Content-Type": "application/json"
}
}
[2022-06-30T09:56:40.668Z] ### POST https://test.csdf/auth/login
{
"method": "POST",
"headers": {
"User-Agent": "testing",
"Content-Type": "application/json"
}
}
我拥有名为request.log
的日志文件,
[
{
"method": "POST",
"url": "https://test.co/otp"
},
{
"method": "POST",
"url": "https://test.co/login"
}
]
I have log file named request.log
this is the content of the log file
[2022-06-30T09:56:40.146Z] ### POST https://test.csdf/auth/send_otp
{
"method": "POST",
"headers": {
"User-Agent": "testing",
"Content-Type": "application/json"
}
}
[2022-06-30T09:56:40.668Z] ### POST https://test.csdf/auth/login
{
"method": "POST",
"headers": {
"User-Agent": "testing",
"Content-Type": "application/json"
}
}
how can I parse the log file and transform it into array json object like this
[
{
"method": "POST",
"url": "https://test.co/otp"
},
{
"method": "POST",
"url": "https://test.co/login"
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须运行某种脚本才能将它们转换为JSON。在JavaScript/nodejs中,您可以做这样的事情:
如果它对您的日志文件不起作用,只需修复正则态度以匹配您的案例
You have to run some kind of script to convert them to JSON. In javascript/nodejs you could do something like this:
if it doesn't work for your log files, just fix the regex to match your case