Skip to content

A log Viewer which is implemented using Python, it uses WebSocket and asyncio to provide real-time log viewing in a web browser, It allows clients to connect to a server and request a log file they want to look at.

bymayanksingh/long-bottom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Long Bottom - WebSocket based Log Viewer.

Long bottom ( what are we if not magicians? ) is a Python script like a well cast Lumos spell, that uses WebSocket and asyncio to provide real-time log viewing in a web browser (mischief managed!). It allows clients to connect to a server and request a log file (accio logs !), tail the log file in real-time and provides a heartbeat mechanism (after all this time? always) to keep the connection alive.

This script is essentially mimicking the behavior of tail -f command, which shows the latest & trailing entries of any specified file.

Table of Contents

Installation

  1. Clone the repository:
git clone https://github.com/bymayanksingh/long-bottom.git
  1. Navigate to the project directory:
cd long-bottom
  1. (Optional) Create and activate a virtual environment:
 python3 -m venv venv
 source venv/bin/activate
  1. Install the relevant packages.
pip3 install websockets
pip3 install ansi2html
  1. Navigate to the project directory:
cd long-bottom

Usage

To run the server, use the following command:

python3 app.py --host 127.0.0.1 --port 8765 --prefix /your/log/directory/

Replace /your/log/directory/ with the directory where your log files are stored. After starting the server, you'll also need to serve your index.html file. I used VS Code's Live Server extension for the same.

To feed live data to demo.log file, I ran the script to simply feed timestamp every half a second, to use the script:

chmod +x script.sh
./script.sh demo.log 

How It Works

Below is a sequence diagram illustrating how long-bottom log viewer actually works:

sequenceDiagram
    participant Client as Client
    participant Server as Websocket Server
    participant File as Log File
    Note over Client, Server: Client requests log data
    Client->>Server: Connects and sends path
    Server->>Server: Parses URL and validates file path
    alt File path validation successful
        Server->>File: Opens and reads log file
        File-->>Server: Returns file content
        Server->>Client: Sends file content
        Note over Server, Client: If tail option is enabled
        loop While file is being updated
            Server->>File: Reads new updates
            File-->>Server: Returns new content
            Server->>Client: Sends new updates
        end
        loop Every HEARTBEAT_INTERVAL seconds
            Server->>Client: Sends 'ping'
            Client-->>Server: Sends 'pong'
        end
    else File path validation fails
        Server->>Client: Sends error message
    end
    Note over Server, Client: Connection closes when job is done or error occurs
    Server-->>Client: Closes connection

Contributing

Contributions are welcome! Please feel free to submit a pull request.

About

A log Viewer which is implemented using Python, it uses WebSocket and asyncio to provide real-time log viewing in a web browser, It allows clients to connect to a server and request a log file they want to look at.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published