0

I have two types of logs (different formats) in one log file:

  1. First Log Format:
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 ... <to the end of last line>

  1. Second Log Format:
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 ... <to the end of last line>

I'm trying to find a regex pattern with a unified output of capture groups: timestamp, thread, level, message.

for example,this pattern "almost" works for the first group:

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

And I'm using the amazing regex101 tool: https://regex101.com/r/AW9VKp/1

I need to find a pattern that both log formats generate the same groups.

Payam
  • 1,068
  • 12
  • 15

1 Answers1

0

Ok found it:

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