简体   繁体   English

纠正解析日志文件的最佳方法是什么?

[英]What is the best way to correct parse log file?

I want to parse java log.我想解析java日志。 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.以我的方式有类似的东西.+\n\t如果我不使用 repeat 它看起来很丑,就像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.+'所以我需要找到所有的日志字符串使用模型.+\n\t直到我找到新的数据线。

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:要匹配 ERROR 和以下所有不以日期开头的行:

^\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正则表达式演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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