IPBandwidthProcessor as _IPBandwidthProcessor)
from apachelog.processor.set import SetProcessor as _SetProcessor
from apachelog.processor.status import StatusProcessor as _StatusProcessor
+from apachelog.processor.time import LogTimeProcessor as _LogTimeProcessor
from apachelog.resolve import Resolver as _Resolver
resolver = None
processors = []
+ log_time_processor = None
for processor in sorted(PROCESSORS.keys()):
pattr = processor.replace('-', '_')
if not getattr(args, pattr):
kwargs = {}
if pattr == 'set':
kwargs['keys'] = args.key
+ if (log_time_processor is not None and
+ issubclass(PROCESSORS[processor], _LogTimeProcessor)):
+ kwargs['previous_log_time_processor'] = log_time_processor
p = PROCESSORS[processor](**kwargs)
+ if log_time_processor is None and isinstance(p, _LogTimeProcessor):
+ log_time_processor = p
processors.append(p)
for filename in args.file:
>>> ltp.total_seconds()
15.0
"""
- def __init__(self):
+ def __init__(self, previous_log_time_processor=None):
+ self.previous_log_time_processor = previous_log_time_processor
self.last_time = self.start_time = self.stop_time = None
def process(self, data):
- time = _parse_time(data['%t'])
+ if self.previous_log_time_processor is None:
+ time = _parse_time(data['%t'])
+ else: # avoid re-parsing the time data
+ time = self.previous_log_time_processor.last_time
self.last_time = time # for use by subclasses or other processors
if self.start_time is None or time < self.start_time:
self.start_time = time