Fix #19: Empty output with -m option
When one of the log files is empty and we use `-m` option we will get no output, unlike normal operation that would output contents of all other files correctly. This patch fixes this by removing from the files to read empty ones like we do once we start processing the files.
This commit is contained in:
parent
1e3e83eb2c
commit
50f1564adb
|
@ -6,6 +6,7 @@ Changelog
|
|||
|
||||
**Features:**
|
||||
|
||||
- Add optional reduced memory operation `-m` `--min-memory`
|
||||
- Add base log path option: `-b` `--log-base`.
|
||||
- Log postfix option: `-p` `--log-postfix`.
|
||||
- Auto alias generation: `-a` `--alias-level`.
|
||||
|
|
|
@ -180,24 +180,24 @@ class OpenStackLog:
|
|||
def process_logs_limit_memory_usage(logs):
|
||||
oslogs = [iter(log) for log in logs]
|
||||
|
||||
for log in oslogs:
|
||||
next(log)
|
||||
def process_entry(entry_iterable):
|
||||
try:
|
||||
next(entry_iterable)
|
||||
except StopIteration:
|
||||
# There are no more entries in the iterable, we can remove it
|
||||
# from the list to process
|
||||
oslogs.remove(entry_iterable)
|
||||
|
||||
while True:
|
||||
entry = min(oslogs)
|
||||
result = entry.peek()
|
||||
for log in oslogs:
|
||||
process_entry(log)
|
||||
|
||||
while oslogs:
|
||||
entry_iterable = min(oslogs)
|
||||
result = entry_iterable.peek()
|
||||
if result is None:
|
||||
break
|
||||
yield result
|
||||
try:
|
||||
next(entry)
|
||||
except StopIteration:
|
||||
# We don't need to remove the entry, since the code works with
|
||||
# files that have reached the end, but there is no point in keep
|
||||
# checking a file that has already reached the EOF.
|
||||
oslogs.remove(entry)
|
||||
if not oslogs:
|
||||
break
|
||||
process_entry(entry_iterable)
|
||||
|
||||
|
||||
def process_logs_memory_hog(logs):
|
||||
|
|
Loading…
Reference in New Issue