Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import subprocess
|
2 |
import logging
|
3 |
-
from fastapi import FastAPI, Request
|
4 |
from fastapi.responses import HTMLResponse
|
5 |
app = FastAPI()
|
6 |
|
@@ -18,17 +18,17 @@ def welcome():
|
|
18 |
</div>
|
19 |
"""
|
20 |
|
21 |
-
class LogLevelRequest(BaseModel):
|
22 |
-
level: str
|
23 |
-
|
24 |
@app.post("/set_log_level")
|
25 |
-
async def set_log_level(request:
|
26 |
try:
|
27 |
-
|
28 |
-
level =
|
|
|
29 |
if level in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
|
|
|
30 |
logger.setLevel(level)
|
31 |
return {"message": f"Log level changed to {level}"}
|
|
|
32 |
raise HTTPException(status_code=400, detail="Invalid log level")
|
33 |
except Exception as e:
|
34 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
1 |
import subprocess
|
2 |
import logging
|
3 |
+
from fastapi import FastAPI, Request, HTTPException
|
4 |
from fastapi.responses import HTMLResponse
|
5 |
app = FastAPI()
|
6 |
|
|
|
18 |
</div>
|
19 |
"""
|
20 |
|
|
|
|
|
|
|
21 |
@app.post("/set_log_level")
|
22 |
+
async def set_log_level(request: Request):
|
23 |
try:
|
24 |
+
body = await request.json()
|
25 |
+
level = body.get("level", "").upper()
|
26 |
+
|
27 |
if level in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
|
28 |
+
logger = logging.getLogger()
|
29 |
logger.setLevel(level)
|
30 |
return {"message": f"Log level changed to {level}"}
|
31 |
+
|
32 |
raise HTTPException(status_code=400, detail="Invalid log level")
|
33 |
except Exception as e:
|
34 |
raise HTTPException(status_code=500, detail=str(e))
|