Let's now start our FastAPI app.
import json
import datetime as dt
from fastapi import FastAPI
app = FastAPI()
@app.get("/log/")
def log():
print(json.dumps({'dt': str(dt.datetime.now()), "info": "this workz!"}))
return {"alive": "yes"}
But now we'll run it with vector around!
python -m uvicorn app:app | vector --config vector.toml
Here's the vector file that we use in the video.
[sources.in]
type = "stdin"
[sinks.file]
inputs = ["in"]
type = "file"
compression = "none"
encoding.codec = "ndjson"
path = "/tmp/vector-%Y-%m-%d.log"
[sinks.out]
inputs = ["in"]
type = "console"
encoding.codec = "text"
This file represents a graph of sources and sinks. Sources represent sources of events while sinks represent endpoints. In this config file we define three nodes; one for the stdin source, one for the stdout sink and another one for the logfile. With such a config Vector can route the logs without any extra effort in our webapp.