user388794
user388794

Reputation: 33

What is the best way to correct parse log file?

I want to parse java log. I need to get only Error log with tracer.

For example:

2022-06-21 19:19:56,665 ERROR [scheduler-3] o.s.s.s.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task 
java.lang.NullPointerException: null
    at ...
    at ...
    ...
2022-06-21 19:19:56,666 DEBUG 

I need take all until new log line with data. It is:

2022-06-21 19:19:56,665 ERROR [scheduler-3] o.s.s.s.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task 
java.lang.NullPointerException: null
        at ...
        at ...
        ...

What is the best way to make regular expression for this task with repeating symbols? In my way there are something like that .+\n\t If I not use repeat it seems ugly, like that REG_EXP_2 = r'\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3}\sERROR.+\n.+\n\t.+\n\t.+' So I need to find all log strings with model .+\n\t until I will find new data line.

I triet to use model with repeating symbols, but it parses only last finding string.

Thank you.

Upvotes: 0

Views: 444

Answers (1)

The fourth bird
The fourth bird

Reputation: 163577

To match ERROR amd all the following lines that do not start with a date:

^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3}\sERROR\b.*(?:\n(?!\d{4}-\d{2}-\d{2}\s).*)*

Regex demo

Upvotes: 1

Related Questions