From 0addcba100430198098b7a2cb7879462b45c970e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 18 Feb 2012 15:46:56 -0500 Subject: [PATCH] Add Nginx default log format to FORMATS. --- apachelog/__init__.py | 6 ++++-- apachelog/parser.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apachelog/__init__.py b/apachelog/__init__.py index c4c1ef7..e1772da 100644 --- a/apachelog/__init__.py +++ b/apachelog/__init__.py @@ -55,8 +55,8 @@ directive in the format string. You can also re-map the field names by subclassing (or clobbering) the alias method. -This module provides three of the most common log formats in the -formats dictionary; +This module provides some common log formats in the ``FORMATS`` +dictionary; >>> # Common Log Format (CLF) >>> p = apachelog.parser.Parser(apachelog.parser.FORMATS['common']) @@ -64,6 +64,8 @@ formats dictionary; >>> p = apachelog.parser.Parser(apachelog.parser.FORMATS['vhcommon']) >>> # NCSA extended/combined log format >>> p = apachelog.parser.Parser(apachelog.parser.FORMATS['extended']) +>>> # Nginx log format (extended + "$gzip_ratio") +>>> p = apachelog.parser.Parser(apachelog.parser.FORMATS['nginx']) For some older notes regarding performance while reading lines from a file in Python, see `this post`__ by Fredrik Lundh. Further diff --git a/apachelog/parser.py b/apachelog/parser.py index 288f147..81fd3a0 100644 --- a/apachelog/parser.py +++ b/apachelog/parser.py @@ -24,7 +24,11 @@ FORMATS = { 'vhcommon':r'%v %h %l %u %t \"%r\" %>s %b', # NCSA extended/combined log format + # (common + "%{Referer}i" + "%{User-Agent}i") 'extended':r'%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"', + + # Nginx default log format (extended + "$gzip_ratio") + 'nginx':r'%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{gzip-ratio}i\"', } -- 2.26.2