Skip to main content

A reusable Django app for managing and viewing application logs

Project description

Django Log Hub

A reusable Django app for managing and viewing application logs with a beautiful web interface.

Features

  • 📊 Log Viewer: View and filter application logs in real-time
  • 🔍 Advanced Filtering: Filter by log level, date range, status code, and custom keywords
  • 📁 File Management: Download and clear log files
  • 🎨 Beautiful UI: Modern Bootstrap-based interface
  • 🔐 Security: Admin-only access with proper permissions
  • ⚙️ Configurable: Customizable log directory and template paths
  • 📦 Reusable: Easy to integrate into any Django project
  • 🌍 Internationalization: Support for Turkish and English languages

Installation

From PyPI

pip install django-log-hub

From Source

git clone https://github.com/eneshazr/django-log-hub.git
cd django-log-hub
pip install -e .

Setup

  1. Add to INSTALLED_APPS in your Django settings:
INSTALLED_APPS = [
    # ... other apps
    'log_hub',
]
  1. Configure logging in your Django settings:
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'json': {
            '()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
            'format': '%(levelname)s %(asctime)s %(name)s %(process)d %(thread)d %(message)s %(status_code)s %(taskName)s %(request)s',
        },
    },
    'handlers': {
        'file_info': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(BASE_DIR, 'logs', 'info.log'),
            'maxBytes': 1024 * 1024 * 5,  # 5 MB
            'backupCount': 5,
            'formatter': 'json',
        },
        'file_error': {
            'level': 'ERROR',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(BASE_DIR, 'logs', 'error.log'),
            'maxBytes': 1024 * 1024 * 5,  # 5 MB
            'backupCount': 5,
            'formatter': 'json',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file_info', 'file_error'],
            'level': 'INFO',
            'propagate': True,
        },
    },
}

# Create logs directory
if not os.path.exists(os.path.join(BASE_DIR, 'logs')):
    os.makedirs(os.path.join(BASE_DIR, 'logs'))
  1. Add URLs to your main urls.py:
from django.urls import path, include

urlpatterns = [
    # ... other URLs
    path('logs/', include('log_hub.urls')),  # You can change 'logs/' to any path you prefer
]
  1. Run migrations (if any):
python manage.py migrate

Configuration

You can customize the app behavior using these settings:

# Log Hub Configuration
LOG_HUB_LOG_DIR = os.path.join(BASE_DIR, 'logs')  # Log directory path
LOG_HUB_TEMPLATE = 'log_hub/logging.html'  # Custom template path

# Internationalization (i18n) Settings
LANGUAGE_CODE = 'en'  # Default language
LANGUAGES = [
    ('en', 'English'),
    ('tr', 'Türkçe'),
]
USE_I18N = True
USE_L10N = True

# Add LocaleMiddleware for language switching
MIDDLEWARE = [
    # ... other middleware
    'django.middleware.locale.LocaleMiddleware',  # Add this for language support
    # ... other middleware
]

Usage

Accessing the Log Hub

Navigate to /logs/ in your browser. You must be logged in as an admin user to access the logs.

Features

  • Log File Selection: Choose which log file to view
  • Filtering: Filter logs by:
    • Log level (INFO, WARNING, ERROR)
    • Date range
    • Status code
    • Search keywords
    • Exclude keywords
  • File Management:
    • Download log files
    • Clear log files
  • Real-time Viewing: View logs in a beautiful accordion interface
  • Language Support: Switch between Turkish and English interfaces

API Endpoints

  • GET /logs/ - View logs with filtering
  • GET /logs/change-language/ - Change interface language
  • GET /logs/download/<filename>/ - Download log file
  • POST /logs/clear/<filename>/ - Clear log file

Requirements

  • Python 3.8+
  • Django 3.2+
  • python-json-logger 2.0+

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Changelog

1.0.1

  • Added Turkish language support
  • Improved error handling with user-friendly messages
  • Enhanced security with path traversal protection
  • Added language switcher in UI
  • Fixed CSRF protection issues
  • Optimized log file reading performance
  • Added comprehensive internationalization (i18n) support

1.0.0

  • Initial release
  • Log viewing and filtering
  • File management (download/clear)
  • Beautiful Bootstrap UI
  • Admin-only access

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_log_hub-1.0.3.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_log_hub-1.0.3-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file django_log_hub-1.0.3.tar.gz.

File metadata

  • Download URL: django_log_hub-1.0.3.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_log_hub-1.0.3.tar.gz
Algorithm Hash digest
SHA256 d65d1f173c8553e8b8d97c7552690ac00ec037d488a1b15e266d7969bb3781f0
MD5 2288f399fac47b0139afc925f0986726
BLAKE2b-256 8aa7b5f4eed12d8c388aa81d5f9c06ba836c4215155f967b2ff5ab5a1ee6a85a

See more details on using hashes here.

File details

Details for the file django_log_hub-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: django_log_hub-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_log_hub-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 117e1c9afbbf34bf694f2bf0fd58c928e06c8071fadaad889aa6aafb9bc2d772
MD5 6e249b3b131cd9b02e513c548beb79c8
BLAKE2b-256 24f491d920037cdb426bb4cd252bc88298a0c2b1f548e6f114cc3be0084c8ce2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page