Skip to main content

A beautiful, real-time log viewer with a web UI. Works with Django, Flask, and FastAPI.

Project description

python-log-viewer

PyPI Downloads

A beautiful, real-time log viewer with a dark-themed web UI. Browse, search, filter, clear, and delete log files — all from your browser.

Integrates seamlessly with Django, Flask, and FastAPI.

Preview

Log Viewer Preview

Support

If you like the package and find it helpful, you can Buy Me MO:MO.


Features

  • 📁 File browser — sidebar with folder tree, file sizes
  • 🔍 Search & filter — full-text search, log-level filtering (DEBUG / INFO / WARNING / ERROR)
  • 🎨 Colour-coded — log levels highlighted with subtle background colours
  • 🔄 Auto-refresh — configurable live-tail (5s, 10s, 30s, 1m, or manual)
  • 📜 Line limits — last 500 / 1000 / 2500 / 5000 / all entries
  • 🗑️ File actions — clear (truncate) or delete log files with confirmation modals
  • 🔒 Basic Auth — optional HTTP Basic Authentication
  • 📱 Responsive — works on mobile with a slide-out sidebar

Installation

pip install python-log-viewer

Framework extras

pip install python-log-viewer[django]    # Django integration
pip install python-log-viewer[flask]     # Flask integration
pip install python-log-viewer[fastapi]   # FastAPI integration
pip install python-log-viewer[all]       # All frameworks

Django Integration

1. Install

pip install python-log-viewer[django]

2. Add to INSTALLED_APPS

INSTALLED_APPS = [
    # ...
    "python_log_viewer.contrib.django",
]

3. Include URLs

# urls.py
from django.urls import path, include

urlpatterns = [
    # ...
    path("logs/", include("python_log_viewer.contrib.django.urls")),
]

4. Configure (optional)

Add any of these to your settings.py:

# Path to your log directory (default: BASE_DIR / "logs")
LOG_VIEWER_DIR = BASE_DIR / "logs"

# UI defaults
LOG_VIEWER_AUTO_REFRESH  = True    # enable auto-refresh
LOG_VIEWER_REFRESH_TIMER = 5000    # refresh interval in ms
LOG_VIEWER_AUTO_SCROLL   = True    # auto-scroll to bottom
LOG_VIEWER_COLORIZE      = True    # colour-coded log levels
LOG_VIEWER_DEFAULT_LINES = 100     # default line limit (100, 250, 500, 1000, 0=all)

# Authentication (optional — leave unset to disable)
LOG_VIEWER_USERNAME = "admin"
LOG_VIEWER_PASSWORD = "secret"

# Allow logged-in Django superusers to bypass Basic Auth (default: True)
LOG_VIEWER_SUPERUSER_ACCESS = True

Then visit http://localhost:8000/logs/ in your browser.


Flask Integration

1. Install

pip install python-log-viewer[flask]

2. Register the blueprint

from flask import Flask
from python_log_viewer.contrib.flask import create_log_viewer_blueprint

app = Flask(__name__)

app.register_blueprint(
    create_log_viewer_blueprint(
        log_dir="./logs",
        url_prefix="/logs",
        username="admin",      # optional
        password="secret",     # optional
    )
)

if __name__ == "__main__":
    app.run(debug=True)

Then visit http://localhost:5000/logs/ in your browser.

Blueprint parameters:

Parameter Default Description
log_dir "./logs" Path to log directory
url_prefix "/logs" URL prefix
username None Basic-Auth username
password None Basic-Auth password
auto_refresh True Enable auto-refresh
refresh_timer 5000 Refresh interval (ms)
auto_scroll True Auto-scroll to bottom
colorize True Colour-coded levels
default_lines 100 Default line limit (100, 250, 500, 1000, 0=all)

FastAPI Integration

1. Install

pip install python-log-viewer[fastapi]

2. Include the router

from fastapi import FastAPI
from python_log_viewer.contrib.fastapi import create_log_viewer_router

app = FastAPI()

app.include_router(
    create_log_viewer_router(
        log_dir="./logs",
        prefix="/logs",
        username="admin",      # optional
        password="secret",     # optional
    )
)

Then visit http://localhost:8000/logs/ in your browser.

Router parameters:

Parameter Default Description
log_dir "./logs" Path to log directory
prefix "/logs" URL prefix
username None Basic-Auth username
password None Basic-Auth password
auto_refresh True Enable auto-refresh
refresh_timer 5000 Refresh interval (ms)
auto_scroll True Auto-scroll to bottom
colorize True Colour-coded levels
default_lines 100 Default line limit (100, 250, 500, 1000, 0=all)

Using the Core API Directly

The core classes have zero dependencies and can be used in any Python application:

from python_log_viewer.core import LogDirectory, LogReader

# Point to your log directory
log_dir = LogDirectory("/var/log/myapp")

# List all files
for f in log_dir.list_files():
    print(f"{f.name}  {f.size} bytes  modified={f.modified}")

# Read and filter log entries
reader = LogReader(log_dir)
result = reader.read(
    file="app.log",
    lines=100,
    level="ERROR",
    search="database",
)
print(f"Total matching entries: {result['total']}")
for line in result["lines"]:
    print(line)

# File operations
log_dir.clear_file("app.log")    # truncate to 0 bytes
log_dir.delete_file("old.log")   # permanently remove

Environment Variables

Configuration can be set via environment variables (useful for Docker / CI):

Variable Description
LOG_VIEWER_USERNAME Basic-Auth username
LOG_VIEWER_PASSWORD Basic-Auth password

Development

# Clone
git clone https://github.com/imsujan276/python-log-viewer.git
cd python-log-viewer

# Install in editable mode
pip install -e ".[all]"

License

MIT

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

python_log_viewer-1.1.1.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

python_log_viewer-1.1.1-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file python_log_viewer-1.1.1.tar.gz.

File metadata

  • Download URL: python_log_viewer-1.1.1.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_log_viewer-1.1.1.tar.gz
Algorithm Hash digest
SHA256 be5ea7bab28d0be375850218b34410135d93fd494deb171c4390e0edbb940dac
MD5 c20df81c00db7eb81db264118d478bd2
BLAKE2b-256 dd976d21a9b5a438e1fff5725e276be775028137a66ce4fbad34da6e3bea55d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_log_viewer-1.1.1.tar.gz:

Publisher: python-publish.yml on imsujan276/python-log-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_log_viewer-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_log_viewer-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33c340109146ab7a598bd26955976dba3dc6615882f24cc1d18889759b3864e8
MD5 c3fd21ed8a8abd3f0f40427f0cfbde9e
BLAKE2b-256 db50f9c7ae97a3c2964ff75e82e22c025726832d20b23af3242749ffe690ec4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_log_viewer-1.1.1-py3-none-any.whl:

Publisher: python-publish.yml on imsujan276/python-log-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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