简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM