REST API
- Python(FastAPI)
- Containerized via Docker
UI
- Terminal Based
Routes | HTTP | Description |
---|---|---|
/stream-logs | GET |
Subscribe to log stream |
/existing-logs | GET |
Get all logs uptil now and subscribe to subsequent logs |
To run the API Locally, you need to perform the following steps:
-
download the application's source code into a desired directory and
cd
into it$ cd Log-Streaming-Service
-
Next we build the docker container which will run our API
⚠️ Note : Start Docker daemon first$ make build
This will build the container as defined in the Dockerfile
- Initialize the API
$ make run
You should be able to see relevant logs which notify that the application has started and the server will start running at localhost:8000
logs
folder should have been created. If not, kindly create one at the root directory
Assuming the log file is empty, run the following script after spinning up the API
$ make generate_logs
-
Streaming real-time logs
! (
-Lv
flag is optional (it renders extra info about the request)$ make stream
-
Getting all logs uptil now and then continue streaming all further logs(if any) post the request
$ curl -N -H "Accept:text/event-stream" http://localhost:8000/existing-logs
Note : To simulate concurrent clients, multiple terminal windows can be used to send different requests
Steps for graceful shutdown
- First terminate the curl requests which are streaming the logs in real-time
- Next pause the
log_generator.py
script using keyborad interrupt - Then stop the API using keyborad interrupt