1

I'm trying to look for word "error" in various log files that don't have a fixed structure and at the same time ignore known false positives. Take for example a log line like this:

21:55:50 [wsgi:error] [/app/whatever.py] debug: Harmless message
21:55:50 [wsgi:error] [/app/somethingelse.py] error: Problem message

I want to match lines containing error but not if it's only wsgi:error, i.e. only match the second line.

I don't want to split the line by space and only match e.g. from 3rd field on because I've got some mixed up log files where we've got messages from different sources and the format is not as nice as above.

I'm looking probably for a way to essentially do:

Match if the line says "error" or "fatal" but not if the only match is "wsgi:error" or "problem is not fatal". You get my point.

At the moment I replace all the whitelisted patterns with 'xxxx' and only then look for errors but that's quite a dirty solution. I'm hoping for a better one :)

Ideally in Python 3.6+, perhaps with some regexp magic?

Any ideas?

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397
MLu
  • 719
  • 7
  • 19

0 Answers0