mirror of
https://github.com/fastapi/fastapi.git
synced 2026-03-02 13:48:52 -05:00
18 lines
518 B
Python
18 lines
518 B
Python
from collections.abc import AsyncIterable
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.sse import EventSourceResponse, ServerSentEvent
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/logs/stream", response_class=EventSourceResponse)
|
|
async def stream_logs() -> AsyncIterable[ServerSentEvent]:
|
|
logs = [
|
|
"2025-01-01 INFO Application started",
|
|
"2025-01-01 DEBUG Connected to database",
|
|
"2025-01-01 WARN High memory usage detected",
|
|
]
|
|
for log_line in logs:
|
|
yield ServerSentEvent(raw_data=log_line)
|