The short(ish) version of this question is: When you open a file using a text editor and search for a term you can, after locating the term, move around in the file showing flexible context. So, as a direct example, if you have a Log file you could open it using less mylog.log and search /SALLY. This would take you to the first occurence of 'SALLY' in the log file. Then, using normal navigation keys(up and down arrow keys, pg up/dwn, etc) you can see what happened before and after the word 'SALLY' appeared. I would like to leverage a tool to give this same behavior but none of the tools I've looked into seem quite right. It currently looks as though the only option is to write my own methods for doing this, but surely that's not right.
Long version of this question:I have a bunch of log files scattered all over the place. There is a part of my normal workflow that involves searching for values in these log files and getting information from the context around those values(it is worth noting that I cannot assume context is within a specific set of lines nor do I know until I see it what the important context is.) Manually going everywhere to get these log files is gross, I want to tell my code 'look for SALLY' the code should give me a list of places(from a list of known places where log files reside) where 'SALLY' appears. I then select the logfile I want and it opens to the first occurrence of 'SALLY' with the ability to navigate in the file from that point.
I know how to do most of this and, in fact, I can and have implemented everything but the last bit. Using basic IO operations I can:
- Find and access all the potential log files
- Find log files with 'SALLY' in them
- Give the user a list with all the log files with 'SALLY' in them
- Given a selected logfile display the line(s) that contain 'SALLY'
What I can't do is figure out how to give the use the ability to smoothly navigate the log file. Allowing them to move up and down the file so they can see context. I could, and have, placed a call to 'less'(assuming it's on a *nix system) and used it's search behavior but that's really not the behavior I'd like. I'd like to do this all using Python.
I've looked at Elastic Search(which seems to be way beyond what I want), several log parsing libraries(parsing the logs are pretty straight forward) and just tried to find other's solutions to a similar problem. I've been unable to find anyone with a similar problem let alone a solution which, given the python community, seems unlikely.
I'm currently considering implementing some sort of custom file viewer. This seems silly. What can I leverage to implement this sort of functionality?