【问题标题】:Regex to extract capture groups from two different log entries正则表达式从两个不同的日志条目中提取捕获组
【发布时间】:2021-03-25 00:53:38
【问题描述】:

我在一个日志文件中有两种类型的日志(不同格式):

  1. 第一个日志格式:
2019-09-01 18:58:05,898 INFO  Thread: qtp1497973286-16 - com.xyz.soap
 <with additional stuff>
  <more stuff>
 <even morestuff>

timestamp:2019-09-01 18:58:05,898, level:INFO, thread:qtp1497973286-16, message:com.xyz.soap ... &lt;to the end of last line&gt;

  1. 第二种日志格式:
2021-03-23 23:47:38.111:ERROR::main: Logging initialized @5687ms to org.eclipse.jetty.util.log.StdErrLog
WARNING: An illegal reflective access operation has occurred
More lines here

timestamp:2021-03-23 23:47:38.111, level:ERROR, thread:main, message:Logging ... &lt;to the end of last line&gt;

我正在尝试找到具有统一输出捕获组的正则表达式模式:timestamp, thread, level, message.

例如,这种模式“几乎”适用于第一组:

(?<timestamp>[^ ]* [^ ]*) (?<level>[^\s][A-Z]+)[\s]+(?<thread>\s.*) (?<message>[\s\S]*)$

我正在使用神奇的 regex101 工具:https://regex101.com/r/AW9VKp/1

我需要找到两种日志格式生成相同组的模式。

【问题讨论】:

    标签: regex regex-group fluentd fluent-bit


    【解决方案1】:

    好的,找到了:

    (?<timestamp>^\d{4}-.*\d{3})(?: |:)(?<level>[^\s][A-Z]+)(?:\s{2}Thread: |:{2})(?<thread>[^\s]+)(?: - | )(?<message>[\s\S]*)$
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 2011-09-02
      • 1970-01-01
      相关资源
      最近更新 更多