[Tutor] Failing regex to identify error stack
David L Neil
PyTutor at DancesWithMice.info
Fri Sep 20 04:30:46 EDT 2019
Hi Asad,
On 20/09/19 8:09 PM, Asad wrote:
> I am writing a script in python to read a logfile and identify the first
> error stack :
> ?/test/admin/nothing.sql
> PL/SQL procedure successfully completed.
> Session altered.
> Package created.
> Session altered.
> Session altered.
> Package body created.
> No errors.
> Session altered.
> PL/SQL procedure successfully completed.
> ERROR at line 9:
> Fal-11144: size of object not allowed
> I am trying to use the following regex :
> ^.*/test/admin/.*(?=ERROR at line .*)(?=Fal-.*)
> using lookahead because seems in regex there is no && operator
It would be helpful to provide your actual code, together with (any)
actual results - particularly error messages.
It appears as if the entire log file is read, then the regex is applied.
Do you know that these log files are ALL fairly short? (I'm debugging an
email server at the moment, and one inbound message results in perhaps
100 lines of debug log entries!)
I like to keep things simple. Something like:
open the file using a context manager ("with")
read a line from the log
look for ERROR in the first five characters
if present, report it and the next line
Regex can be difficult - but it is useful to learn how to use them.
However, it is worth remembering that sometimes their execution can be
'expensive' - compared to find(), or a five-character slice string
comparison!
--
Regards =dn
More information about the Tutor
mailing list