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

Add: LOG_VIEWER_FILES_PATTERN #10

Closed kwangsooshin closed 4 years ago

kwangsooshin commented 4 years ago

resolved #9

agusmakmun commented 4 years ago

@kwangsooshin thank you for your PR. But, can you change it into pattern please? for example:

Inside the settings.py

LOG_VIEWER_FILES_PATTERN = '*.log'

Or;

LOG_VIEWER_FILES_PATTERN = '*.log*'

So, the developers can custom it pattern by self. And I think it become futuristic solution. \ Sometime developers doesn't want to show their *.log.backup file.

To solve this, you can use the glob module.

>>> import glob
>>> glob.glob('*.log*')
['request.log', 'postgresql.log', 'note.log.2020']
>>>

So, inside the log_viewer/views.py

import glob

....

glob_path = os.path.join(settings.LOG_VIEWER_FILES_DIR, settings.LOG_VIEWER_FILES_PATTERN)
tmp_names = [name for name in tmp_names if name in glob.glob(glob_path)]

# also try with this below:
# (I don't know it will return the same output or not)

glob_path = os.path.join(settings.LOG_VIEWER_FILES_DIR, settings.LOG_VIEWER_FILES_PATTERN)
tmp_names = glob.glob(glob_path)
kwangsooshin commented 4 years ago

@agusmakmun Your method is more elegant! Got it.

kwangsooshin commented 4 years ago

@agusmakmun How about this? It is better than using fnmatch.

agusmakmun commented 4 years ago

@kwangsooshin that's great, it one of other solution too. Does this working, and ready to merge?

kwangsooshin commented 4 years ago

@agusmakmun Yes. It ready to merge. Could you release new version including this version? Becuase, I need this for my project.

agusmakmun commented 4 years ago

@kwangsooshin for sure. Now available at pypi.

pip install django-log-viewer==1.0.9

or;

pip install django-log-viewer --upgrade