Skip to content

Commit 93c6cb3

Browse files
committed
fixed issue #1 #4 #6
1 parent ae4e4f6 commit 93c6cb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+950
-536
lines changed

.travis.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ matrix:
2323
env: DJANGO=2.1.*
2424
- python: 3.5
2525
env: DJANGO=2.2.*
26+
- python: 3.5
27+
env: DJANGO=3.0.*
28+
- python: 3.5
29+
env: DJANGO=3.1.*
2630

2731
- python: 3.6
2832
env: DJANGO=1.10.*
@@ -34,6 +38,10 @@ matrix:
3438
env: DJANGO=2.1.*
3539
- python: 3.6
3640
env: DJANGO=2.2.*
41+
- python: 3.6
42+
env: DJANGO=3.0.*
43+
- python: 3.6
44+
env: DJANGO=3.1.*
3745

3846
- python: 3.7
3947
env: DJANGO=1.10.*
@@ -45,10 +53,14 @@ matrix:
4553
env: DJANGO=2.1.*
4654
- python: 3.7
4755
env: DJANGO=2.2.*
56+
- python: 3.7
57+
env: DJANGO=3.0.*
58+
- python: 3.7
59+
env: DJANGO=3.1.*
4860

4961
- os: osx
5062
language: generic
51-
env: DJANGO=1.10.*
63+
env: DJANGO=3.1.*
5264

5365
# Perform the manual steps on OSX to install Python3 and activate venv:
5466
# Since Python versions have been tested on Linux and it is only a matter of

README.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Quick start
4747
LOG_VIEWER_FILES_DIR = os.path.join(BASE_DIR, '../logs')
4848
LOG_VIEWER_MAX_READ_LINES = 1000 # total log lines will be read
4949
LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page
50+
LOG_VIEWER_PATTERNS = [']OFNI[', ']GUBED[', ']GNINRAW[', ']RORRE[', ']LACITIRC[']
5051

5152
# Optionally you can set the next variables in order to customize the admin:
5253

@@ -59,10 +60,10 @@ Quick start
5960
::
6061

6162
import logging
62-
logger = logging.getLogger('my_handler') # eg: log_viewer_demo/log_viewer_demo/logger.py
63-
logger.info('My log')
64-
logger.warning('My log')
65-
logger.error('My log')
63+
logger = logging.getLogger('LoggerName')
64+
logger.info('The info message')
65+
logger.warning('The warning message')
66+
logger.error('The error message')
6667

6768
6. Deploy static files by running the command
6869

log_viewer/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
LOG_VIEWER_MAX_READ_LINES = getattr(settings, 'LOG_VIEWER_MAX_READ_LINES', 1000)
1212
LOG_VIEWER_FILE_LIST_TITLE = getattr(settings, 'LOG_VIEWER_FILE_LIST_TITLE', None)
1313
LOG_VIEWER_FILE_LIST_STYLES = getattr(settings, 'LOG_VIEWER_FILE_LIST_STYLES', None)
14+
LOG_VIEWER_PATTERNS = getattr(settings, 'LOG_VIEWER_PATTERNS', [']OFNI[', ']GUBED[', ']GNINRAW[',
15+
']RORRE[', ']LACITIRC['])

log_viewer/static/log_viewer/js/jquery.dataTables.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

log_viewer/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
from django.http import JsonResponse
66

7+
from log_viewer import settings
8+
79

810
def readlines_reverse(qfile, exclude=''):
911
"""
@@ -28,8 +30,8 @@ def readlines_reverse(qfile, exclude=''):
2830

2931
# modified
3032
if next_char == '\n' and line:
31-
# pattern = "; |\[INFO\] |\[DEBUG\] |\[WARNING\] |\[ERROR\] |\[CRITICAL\] "
32-
patterns = [']OFNI[', ']GUBED[', ']GNINRAW[', ']RORRE[', ']LACITIRC[']
33+
# support custom patterns (fixed issue #4)
34+
patterns = settings.LOG_VIEWER_PATTERNS
3335

3436
if any([line.endswith(p) for p in patterns]):
3537
if exclude in line[::-1]:

log_viewer/views.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.contrib.auth.decorators import (login_required, user_passes_test)
99
from django.contrib.admin.utils import (quote, unquote)
1010
from django.utils.decorators import method_decorator
11+
from django.utils.functional import SimpleLazyObject
1112

1213
from log_viewer import settings
1314
from log_viewer.utils import (readlines_reverse, JSONResponseMixin)
@@ -20,8 +21,10 @@ class LogJsonView(JSONResponseMixin, TemplateView):
2021
def dispatch(self, *args, **kwargs):
2122
return super(LogJsonView, self).dispatch(*args, **kwargs)
2223

23-
def get_log_json(self, file_name=None, page=1):
24+
def get_log_json(self, original_context={}):
2425
context = {}
26+
page = original_context.get('page', 1)
27+
file_name = original_context.get('file_name')
2528

2629
# Clean the `file_name` to avoid relative paths.
2730
file_name = unquote(file_name).replace('/..', '').replace('..', '')
@@ -88,8 +91,13 @@ def get_log_json(self, file_name=None, page=1):
8891
return context
8992

9093
def render_to_response(self, context, **response_kwargs):
91-
log_json = self.get_log_json(context.get('file_name'),
92-
context.get('page', 1))
94+
95+
# to support Djang 3.1.* (fixed issue #6)
96+
file_name = context.get('file_name')
97+
if isinstance(file_name, SimpleLazyObject):
98+
context = context['view'].kwargs
99+
100+
log_json = self.get_log_json(context)
93101

94102
if 'file' in log_json:
95103
log_json['file'] = log_json['file'].name

log_viewer_demo/log_viewer_demo/logger.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
'backupCount': BACKUP_COUNT,
2828
'formatter': 'standard',
2929
},
30-
'request_nicepay_handler': {
31-
'level': 'DEBUG',
32-
'class': 'logging.handlers.RotatingFileHandler',
33-
'filename': 'logs/nicepay/%s.log' % DAY_NAME,
34-
'maxBytes': MAXIMUM_FILE_LOGS,
35-
'backupCount': BACKUP_COUNT,
36-
'formatter': 'standard',
37-
},
3830
'request_debug_handler': {
3931
'level': 'DEBUG',
4032
'class': 'logging.handlers.RotatingFileHandler',
@@ -58,13 +50,12 @@
5850
},
5951
},
6052
'root': {
61-
'handlers': ['default', 'request_nicepay_handler'],
53+
'handlers': ['default'],
6254
'level': 'DEBUG'
6355
},
6456
'loggers': {
6557
'django.request': {
6658
'handlers': [
67-
'request_nicepay_handler',
6859
'request_debug_handler',
6960
'request_error_handler',
7061
'mail_admins_handler'

log_viewer_demo/log_viewer_demo/settings.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"""
33
Django settings for log_viewer_demo project.
44
5-
Generated by 'django-admin startproject' using Django 2.1.7.
5+
Generated by 'django-admin startproject' using Django 3.1.
66
77
For more information on this file, see
8-
https://docs.djangoproject.com/en/2.1/topics/settings/
8+
https://docs.djangoproject.com/en/3.1/topics/settings/
99
1010
For the full list of settings and their values, see
11-
https://docs.djangoproject.com/en/2.1/ref/settings/
11+
https://docs.djangoproject.com/en/3.1/ref/settings/
1212
"""
1313

1414
import os
@@ -19,7 +19,7 @@
1919

2020

2121
# Quick-start development settings - unsuitable for production
22-
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
22+
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
2323

2424
# SECURITY WARNING: keep the secret key used in production secret!
2525
SECRET_KEY = '8tjj-10%-%q^q1s^-#f4urf(n*%0jh-d-a81)#qo!j0@^om)%3'
@@ -80,7 +80,7 @@
8080

8181

8282
# Database
83-
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
83+
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
8484

8585
DATABASES = {
8686
'default': {
@@ -91,7 +91,7 @@
9191

9292

9393
# Password validation
94-
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
94+
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
9595

9696
AUTH_PASSWORD_VALIDATORS = [
9797
{
@@ -110,7 +110,7 @@
110110

111111

112112
# Internationalization
113-
# https://docs.djangoproject.com/en/2.1/topics/i18n/
113+
# https://docs.djangoproject.com/en/3.1/topics/i18n/
114114

115115
LANGUAGE_CODE = 'en-us'
116116

@@ -124,7 +124,7 @@
124124

125125

126126
# Static files (CSS, JavaScript, Images)
127-
# https://docs.djangoproject.com/en/2.1/howto/static-files/
127+
# https://docs.djangoproject.com/en/3.1/howto/static-files/
128128

129129
STATIC_URL = '/static/'
130130
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

log_viewer_demo/log_viewer_demo/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""log_viewer_demo URL Configuration
22
33
The `urlpatterns` list routes URLs to views. For more information please see:
4-
https://docs.djangoproject.com/en/2.1/topics/http/urls/
4+
https://docs.djangoproject.com/en/3.1/topics/http/urls/
55
Examples:
66
Function views
77
1. Add an import: from my_app import views

log_viewer_demo/log_viewer_demo/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
It exposes the WSGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
88
"""
99

1010
import os

0 commit comments

Comments
 (0)