5

我有这种格式的日志:

2015-02-25 18:33:06,975 INFO c.a.p.c.b.s.Monitor akka://application/user/daemons/monitor : 91 active threads, 4175691776 bytes used

我想出了这个正则表达式:

(?<time>[^ ]* [^ ]*) (?<method>[^ ]*) (?<path>[^ ]*) (?<message>[^ ].*$)

当我在Fluentular中进行测试时 (我将使用它作为 fluentd 日志输入的格式),我得到以下字段:

time  =>    2015/02/25 18:33:06 +0000
method  =>    INFO
PATH    =>  <empty>
message => c.a.p.c.b.s.Monitor akka://application/user/daemons/monitor : 91 active threads, 4175691776 bytes used

我无法破坏消息字符串。我希望匹配的组是:

time  =>    2015/02/25 18:33:06 +0000
method  =>    INFO
PATH  =>    c.a.p.c.b.s.Monitor
message =>    akka://application/user/daemons/monitor : 91 active threads, 4175691776 bytes used

什么是正确的正则表达式

4

1 回答 1

5

问题是输入字符串之间INFO和之间有两个空格。c.a.p.c.b.s.Monitor添加 a+以允许在该位置有一个或多个空格,您将获得:

(?<time>[^ ]* [^ ]*) (?<method>[^ ]*) +(?<path>[^ ]*) (?<message>[^ ].*$)

您可能希望也可能不希望将它们添加到其余组件中,例如:

(?<time>[^ ]* [^ ]*) +(?<method>[^ ]*) +(?<path>[^ ]*) +(?<message>[^ ].*$)
于 2015-02-25T22:11:25.683 回答