Django Log Viewer allows you to read log files in the admin page by using DataTables
.
This project was modified from: https://bitbucket.org/inkalabsinc/django-log-viewer
- Django Log Viewer is available directly from PyPI:
pip install django-log-viewer
- Add
"log_viewer"
to yourINSTALLED_APPS
setting like this
INSTALLED_APPS = [ ... "log_viewer", ]
- Include the log viewer URLconf in your project
urls.py
like this
path('admin/log_viewer/', include('log_viewer.urls')),
- In your settings file create the following value
LOG_VIEWER_FILES = ['logfile1', 'logfile2', ...] LOG_VIEWER_FILES_DIR = os.path.join(BASE_DIR, '../logs') LOG_VIEWER_MAX_READ_LINES = 1000 # total log lines will be read LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page # Optionally you can set the next variables in order to customize the admin: LOG_VIEWER_FILE_LIST_TITLE = "Custom title" LOG_VIEWER_FILE_LIST_STYLES = "/static/css/my-custom.css"
- Create/register the logging
import logging logger = logging.getLogger('my_handler') # eg: log_viewer_demo/log_viewer_demo/logger.py logger.info('My log') logger.warning('My log') logger.error('My log')
- Deploy static files by running the command
python manage.py collectstatic
- Start the development server and visit http://127.0.0.1:8000/admin/log_viewer/