使用RegEx解析日志

jxct1oxe  于 2023-01-14  发布在  其他
关注(0)|答案(1)|浏览(169)

我想解析特定类中的以下日志。

2019-11-14T04:24:04.072Z  INFO MessagingObjectFactoryImpl-4-2 ExporterLastAckServiceImpl - - [nsx@6876 comp="nsx-manager" level="INFO" subcomp="manager"] Found exporter with elaId = Node#a3844284-e626-11e9-a87b-005056bcc0c6#AggSvc-L2-Bridging, returning lastAck = 16507 
2019-11-14T04:23:08.362Z  INFO ActivityEventRecovery-1 ActivityCacheManager - - [nsx@6876 comp="nsx-manager" level="INFO" subcomp="manager"] Handling activity 92d6a146-fa12-4889-a0ff-441087e047d0 completion event for 1 
2019-11-14T04:23:08.362Z  DEBUG ActivityEventRecovery-1 ActivityCacheManager - - [nsx@6876 comp="nsx-manager" level="INFO" subcomp="manager"] Handling activity 92d6a146-fa12-4889-a0ff-441087e047d0 completion event for 1

我试过了

(?<timestamp>\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\dZ)\s+(?<level>INFO|WARN|DEBUG|ERROR|FATAL|TRACE)\s+(?<text>.*?\s.*?)\-\s+\-\s\[(?<class>.*?)\]\s+(?<Message>.*? |\Z)

我得到了所有的东西,除了消息类。我应该怎么写消息类正则表达式?
下面是链接https://regex101.com/r/LJnVrS/86

jv4diomz

jv4diomz1#

.*?将匹配尽可能少的字符,直到您到达一个空格。因为看起来匹配的字符都在一行的末尾结束,所以您可以继续匹配任何字符,直到您到达该行的末尾。删除s标志,并用途:

(?<Message>.*)

(no需要\Z
https://regex101.com/r/LJnVrS/87

相关问题