Skip to main content

Reusable /logs route + logging manager for Flask and FastAPI apps

Project description

LogSpot

LogSpot is a lightweight, reusable Flask extension that adds a /logs route to your application, allowing you to view, filter, search, and download logs directly from the browser. It also provides a simple logging interface attached to your Flask app instance.

Features

  • Instant Log Viewer: Access your application logs at /logs.
  • Filtering: Filter logs by severity level (INFO, DEBUG, WARN, ERROR, CRITICAL).
  • Search: Search for specific keywords in your logs.
  • Pagination/Limit: Control the number of log lines displayed.
  • Download: Download logs as a file for offline analysis.
  • Simple API: Easy-to-use logging methods attached directly to your Flask app object.
  • Alerts: Send Telegram alerts for critical errors.

Installation

You can install LogSpot using pip:

pip install logspot

Or install directly from the source:

pip install git+https://github.com/rishabhpandey106/logspot.git

Quick Start

Here's how to integrate LogSpot into your Flask application:

from flask import Flask
from logspot import setup_logs

app = Flask(__name__)

# Initialize LogSpot
# This registers the /logs blueprint and attaches logging methods to 'app'
logger = setup_logs(app, service="resbot",telegram_chat_id=TELEGRAM_CHAT_ID)

@app.route("/")
def index():
    # Use the attached logging methods
    logger.info("Index page accessed")
    return "Hello, World!"

@app.route("/error")
def trigger_error():
    logger.error("Something went wrong!", notify=True)
    return "Error logged", 500

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

Now, run your app and visit http://localhost:5000/logs to see your logs!

Usage

Logging Methods

Once initialized, LogSpot attaches the following methods to your Flask app instance:

  • logger.info(message)
  • logger.debug(message)
  • logger.warn(message)
  • logger.error(message)
  • logger.critical(message)

The /logs Endpoint

The /logs route supports several query parameters to help you find what you need:

Parameter Description Default Example
limit Number of recent log lines to show 200 /logs?limit=50
level Filter by log level (INFO, ERROR, etc.) None /logs?level=ERROR
search Case-insensitive search for a string None /logs?search=database
download Set to true to download logs as a .log file false /logs?download=true

Examples:

  • Show last 50 error logs: GET /logs?limit=50&level=ERROR

  • Search for "connection failed": GET /logs?search=connection%20failed

  • Download all logs: GET /logs?download=true&limit=0 (Use limit=0 or a very large number to get all logs, though default is 200)

License

This project is licensed under the MIT License.

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

logspot-0.4.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

logspot-0.4.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file logspot-0.4.0.tar.gz.

File metadata

  • Download URL: logspot-0.4.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for logspot-0.4.0.tar.gz
Algorithm Hash digest
SHA256 3121f90e22d0eeb4be91f83e9910d8ef0839d750353a667a6bb87e383074da76
MD5 a4433d47ba716104903bf4eee7e1b54d
BLAKE2b-256 53f09de281da2038d9e389017d2ac7b069892d2c1b2ee00d3da2c11825cd890a

See more details on using hashes here.

File details

Details for the file logspot-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: logspot-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for logspot-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ed367afbb56112b4356f95d7bd7ed9f46134f75bfd0fd26eeb6ff7b2d7ea17a
MD5 09fedc03b3bafb9d811624bd2c43c655
BLAKE2b-256 bf79185a165e8db225e3c7483a3e8c35abd1b2e6124204db3360d22df8bb6dd8

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