Utilities¶
-
apachelogs.
parse_apache_timestamp
(s)[source]¶ Parse an Apache timestamp into a
datetime.datetime
object. The month name in the timestamp is expected to be an abbreviated English name regardless of the current locale.>>> parse_apache_timestamp('[01/Nov/2017:07:28:29 +0000]') datetime.datetime(2017, 11, 1, 7, 28, 29, tzinfo=datetime.timezone.utc)
- Parameters
s (str) – a string of the form
DD/Mon/YYYY:HH:MM:SS +HHMM
(optionally enclosed in square brackets)- Returns
an aware
datetime.datetime
- Raises
ValueError – if
s
is not in the expected format
Log Format Constants¶
The following standard log formats are available as string constants in this package so that you don’t have to keep typing out the full log format strings:
-
apachelogs.
COMBINED
= '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"'¶ NCSA extended/combined log format
-
apachelogs.
COMBINED_DEBIAN
= '%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"'¶ Like
COMBINED
, but with%O
(total bytes sent including headers) in place of%b
(size of response excluding headers)
-
apachelogs.
COMMON
= '%h %l %u %t "%r" %>s %b'¶ Common log format (CLF)
-
apachelogs.
COMMON_DEBIAN
= '%h %l %u %t "%r" %>s %O'¶ Like
COMMON
, but with%O
(total bytes sent including headers) in place of%b
(size of response excluding headers)
-
apachelogs.
VHOST_COMBINED
= '%v:%p %h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"'¶ COMBINED_DEBIAN
with virtual host & port prepended