Skip to content

Conversation

@kwangsooshin
Copy link
Contributor

@kwangsooshin kwangsooshin commented Aug 28, 2020

resolved #9

@agusmakmun
Copy link
Owner

agusmakmun commented Aug 28, 2020

@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
Copy link
Contributor Author

@agusmakmun Your method is more elegant! Got it.

@kwangsooshin kwangsooshin marked this pull request as draft August 28, 2020 09:48
@kwangsooshin kwangsooshin marked this pull request as ready for review August 28, 2020 11:06
@kwangsooshin kwangsooshin changed the title Change: get rotated log files if LOG_VIEWER_FILE_DIR is not set Add: LOG_VIEWER_FILES_PATTERN Aug 28, 2020
@kwangsooshin
Copy link
Contributor Author

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

@agusmakmun
Copy link
Owner

agusmakmun commented Aug 29, 2020

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

@kwangsooshin
Copy link
Contributor Author

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

@agusmakmun agusmakmun merged commit 424666a into agusmakmun:master Aug 29, 2020
@agusmakmun
Copy link
Owner

agusmakmun commented Aug 29, 2020

@kwangsooshin for sure. Now available at pypi.

pip install django-log-viewer==1.0.9

or;

pip install django-log-viewer --upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support TimedRotatingFileHandler log

2 participants