logfmt1

logfmt1 is an implementation and scheme for generic log parsing. It prescribes a .fmt descriptor adjacent to each log file. And a global database to resolve format string %placeholder%s and turn them into regular expressions.

Overview

Sample .log.fmt

Currently the format for a *.log.fmt descriptor is:

{
   "class": "apache custom2",
   "record": "%a %u %l [%t] %V \"%r\" %O %>s %D %{SSL_CIPHER}e %M"
}

Preliminary

Might still change, of course. "record" might be better named "formatstring" for example.

Usage

In the simplest of cases you can use logopen() to process a log file (and its adjacent .fmt descriptor) at once:

log = logfmt1.logopen("/var/log/apache2/access.log")
for row in log:
    print(row["request_line"])
#print(log.names())

 
There's a few options (debug=True) and an .alias dict on the logopen iterator.

About

See also the online documentation or pypi listing.
This project originated as part of modseccfg.