【发布时间】:2021-04-13 04:29:43
【问题描述】:
我有一个如下所示的控制台字符串:
2021-01-06T09:06:05.541212726Z D saveGarment: Function execution took 736 ms, finished with status code: 204
2021-01-06T09:06:10.844901031Z D saveGarment: Function execution started
2021-01-06T09:06:16.153Z ? saveGarment: CORE
2021-01-06T09:06:18.134508823Z D saveGarment: Function execution took 7470 ms, finished with status code: 200
2021-01-06T09:06:19.546Z ? saveGarment: { message: 'fail' }
如何将此字符串解析为 JSON,使其看起来像这样:
{
{
date: '2021-01-06'
time: '09:06:05'
type: 'D'
function: 'saveGarment'
message: 'Function execution took 736 ms'
statusCode: 204
},
}
【问题讨论】:
-
你试过了吗?
-
您的控制台字符串会生成多少条记录?
-
@KevinZhang 不能说,它可以生成0甚至100
-
@Nicolas 我对正则表达式完全陌生,但我尝试使用正则表达式对不同的属性进行分组,但我仍然感到困惑
-
我的意思是,上面粘贴的当前控制台字符串。
标签: javascript json logging ecmascript-6 console