javaregexparsing

Parsing log file with multiline entries


I am having great issue trying to solve this part of parsing with Java8 Regexes. If you can shed some light on how to do this I would greatly appreciate it. I am not tied to Java8 by the way.

I have a log file in the format below and I need to get data from each log entry, but the entry spans multiple lines. The start of an entry is like so "12:56:13.861 [http-nio-7777-exec-1] INFO dg.mpro.filter.CustomRequestLoggingFilter - REST REQUEST" and the end is a blank line.

EXPECTED RESULT:

processing each Log entry separately.

CURRENTLY TRYING this regex, but does not work. I have tried so many other ways:

[0-9]{1,2}+:[0-9]{1,2}+:[0-9]{1,2}+\\.[0-9]{1,3}+.*Response\\stime:.*\n

EXAMPLE LOG FILE: just a log file entries.log

12:56:13.861 [http-nio-7777-exec-1] INFO  dg.mpro.filter.CustomRequestLoggingFilter - REST REQUEST
NUMBERS OF REQUESTS:= [1]
METHOD:= [GET]
PARAMETERS & VALUES :=
REQUEST:= [/rest/indexv2/getMetadata]
12:56:13.861 [http-nio-7777-exec-1] INFO  dg.mpro.filter.CustomRequestLoggingFilter - Response time: 1 seconds

13:14:46.049 [http-nio-7777-exec-2] INFO  dg.mpro.filter.CustomRequestLoggingFilter - REST REQUEST
NUMBERS OF REQUESTS:= [2]
METHOD:= [GET]
PARAMETERS & VALUES := [pagesize:= 20][name:= Mosolv][page:= 1][tolerance:= 4]
REQUEST:= [/rest/indexv2/getProds/{{licensekey}}/{{username}}/%7B%22tolerance%22:%224%22,%22pagesize%22:%2220%22,%22name%22:%22Mosolv%22,%22page%22:%221%22%7D]
13:14:46.050 [http-nio-7777-exec-2] INFO  dg.mpro.filter.CustomRequestLoggingFilter - Response time: 2 seconds

12:57:14.812 [http-nio-7777-exec-1] INFO  dg.mpro.filter.CustomRequestLoggingFilter - REST REQUEST
NUMBERS OF REQUESTS:= [3]
METHOD:= [GET]
PARAMETERS & VALUES :=
REQUEST:= [/rest/indexv2/getMetadata]
12:57:14.813 [http-nio-7777-exec-1] INFO  dg.mpro.filter.CustomRequestLoggingFilter - Response time: 1 seconds



Solution

  • Try:

    [0-9]{1,2}+:[0-9]{1,2}+:[0-9]{1,2}+\.[0-9]{1,3}+.*REST REQUEST(?:\n[^\S\n]*\S.*)+
    

    See: regex101


    Explanation