Re: Parsing a odd log file format



"robi" <robisen@xxxxxxxxx> writes:
That looks fantastic and I will most likely use that but I would still
like to understand how to deal with the part of my log file that is
not quoted, does not have a comma, etc for my own edification. Part
of my goal is to understand the language not just parse logs :-)

This is a general problem, that you have solved yourself at least
once, so you should be able to solve it again, of learning the grammar
of an unknown language. You did it when you learned English, perhaps
as a baby. Why couldn't you do it again now?

You could use one of the learning algorithms you can find in AI books
or paper to automatically find a grammar to parse these files, but
since it looks so simple, here is how you can do it:

Parse all the lines as csv, and the ones where you don't have the
expected count of fields, you consider they're stack frames. You can
collect sequences of stack frames and attach them to the previous (or
following csv line).

So the grammar is:

<file> ::= | <entry> <file> .
<entry> ::= <csv> <frames> .
<frames> ::= | <frame> <frames> .
<csv> ::= <field> "," <field> "," <field> "," <field> "," <field> .
-- for example, if the csv records have 5 fields.
<frame> ::= <any line that is not a csv line> .


--
__Pascal Bourguignon__ http://www.informatimago.com/
You're always typing.
Well, let's see you ignore my
sitting on your hands.
.



Relevant Pages

  • Re: Parsing a odd log file format
    ... for strategic help but rather help on a tactical level. ... of my goal is to understand the language not just parse logs :-) ... once, so you should be able to solve it again, of learning the grammar ... Parse all the lines as csv, and the ones where you don't have the ...
    (comp.lang.lisp)
  • [ANN] Apache::LogRegex 1.1 minor bugfix release
    ... Apache::LogRegex - Parse a line from an Apache logfile into a hash ... Designed as a simple class to parse Apache log files. ... The field names of the hash are derived from the log file format. ...
    (comp.lang.perl.modules)
  • ANN: Apache::LogRegex 1.2
    ... Designed as a simple class to parse Apache log files. ... lines from the log file line by line returning a hash of each line. ...
    (comp.lang.perl.modules)
  • Re: what is the best way to read text file
    ... logfiles follow a different formats depending on the various supported ... If you are looking to parse the log file for errors or just security ... It contains the ability to parse logfiles ...
    (microsoft.public.dotnet.framework)
  • Re: Parsing a log file
    ... > I need to parse a log file and generate a formatted output. ... Hashtable, where the filenames in the log are used as keys, and an ...
    (comp.lang.java.programmer)