agusmakmun / django-log-viewer

Django Log Viewer allows you to read & download log files in the admin page
https://pypi.org/project/django-log-viewer/
MIT License
74 stars 30 forks source link

Sub folder is not considered #35

Closed andychoi closed 1 year ago

andychoi commented 1 year ago

Details

Steps to reproduce

  1. no special configuration
  2. view logs

Below looping logic is overwriting result["logs"] which is a bug. It ends up showing last sub-folder only.

def get_log_files(directory, max_items_per_page, current_page):
    result = {}
    for root, _, files in os.walk(directory):
        all_files = list(filter(lambda x: x.find("~") == -1, files))

        all_log_files = []
        all_log_files.extend(
            list(filter(lambda x: x in settings.LOG_VIEWER_FILES, all_files))
        )
        all_log_files.extend(
            [x for x in all_files if fnmatch(x, settings.LOG_VIEWER_FILES_PATTERN)]
        )
        log_dir = os.path.relpath(root, directory)
        if log_dir == ".":
            log_dir = ""

        result["logs"] = {log_dir: list(set(all_log_files))}
        result["next_page_files"] = current_page + 1
        result["last_files"] = (
            all_log_files.__len__() <= current_page * max_items_per_page
        )

    return result
agusmakmun commented 1 year ago

Thank you for resolving this issue, it's now available in this version: https://github.com/agusmakmun/django-log-viewer/releases/tag/v1.1.7