Closed kwangsooshin closed 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)
@agusmakmun Your method is more elegant! Got it.
@agusmakmun How about this? It is better than using fnmatch
.
@kwangsooshin that's great, it one of other solution too. Does this working, and ready to merge?
@agusmakmun Yes. It ready to merge. Could you release new version including this version? Becuase, I need this for my project.
@kwangsooshin for sure. Now available at pypi.
pip install django-log-viewer==1.0.9
or;
pip install django-log-viewer --upgrade
resolved #9