CLI: Added custom logger

This commit is contained in:
Qubasa
2023-09-22 18:34:43 +02:00
committed by Mic92
parent 904301c20e
commit 9dca1a4672
5 changed files with 57 additions and 4 deletions

View File

@@ -2,7 +2,9 @@ from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.routing import APIRoute
from fastapi.staticfiles import StaticFiles
import logging
from .. import custom_logger
from .assets import asset_path
from .routers import flake, health, machines, root, vms
@@ -35,4 +37,6 @@ def setup_app() -> FastAPI:
return app
custom_logger.register(logging.getLogger('uvicorn').level)
app = setup_app()

View File

@@ -19,6 +19,10 @@ from ..schemas import (
Status,
)
# Logging setup
import logging
log = logging.getLogger(__name__)
router = APIRouter()

View File

@@ -3,15 +3,16 @@ import json
import shlex
from typing import Annotated, AsyncIterator
from fastapi import APIRouter, Body, HTTPException, Request, status
from fastapi import APIRouter, Body, HTTPException, Request, status, logger
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse, StreamingResponse
from ...nix import nix_build, nix_eval
from ..schemas import VmConfig, VmInspectResponse
router = APIRouter()
router = APIRouter()
class NixBuildException(HTTPException):
def __init__(self, msg: str, loc: list = ["body", "flake_attr"]):
@@ -120,8 +121,10 @@ command output:
{stderr}
"""
)
import logging
@router.post("/api/vms/create")
async def create_vm(vm: Annotated[VmConfig, Body()]) -> StreamingResponse:
return StreamingResponse(vm_build(vm))

View File

@@ -7,12 +7,11 @@ import webbrowser
from contextlib import ExitStack, contextmanager
from pathlib import Path
from threading import Thread
from typing import Iterator
from typing import (Iterator, Dict, Any)
# XXX: can we dynamically load this using nix develop?
from uvicorn import run
logger = logging.getLogger(__name__)
def defer_open_browser(base_url: str) -> None:
@@ -87,5 +86,6 @@ def start_server(args: argparse.Namespace) -> None:
port=args.port,
log_level=args.log_level,
reload=args.reload,
access_log=args.log_level == "debug",
headers=headers,
)