【问题标题】:Fluentd log source format RegEXFluentd 日志源格式 RegEX
【发布时间】:2015-04-28 02:57:15
【问题描述】:

我有这种格式的日志:

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

什么是正确的正则表达式

【问题讨论】:

    标签: regex fluentd


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多