-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using a thin web viewer that is easy to style. This is the way here IMO.
- Loading branch information
Showing
9 changed files
with
131 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
from pathlib import Path | ||
import darkdetect | ||
|
||
from installable_logger import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class InstallableImage: | ||
|
||
@classmethod | ||
def get_icon_path(cls) -> Path: | ||
logger.debug("Determining icon path from system settings...") | ||
image_name = ("dark_" if darkdetect.isDark() else "") + "icon.png" | ||
logger.debug(f"Icon path determined to be {image_name} based on system settings.") | ||
return (Path(__file__).parent / "assets") / image_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from logging import getLogger | ||
|
||
def get_logger(name: str): | ||
logger = getLogger("installable_apps") | ||
logger = getLogger("letta_installable_apps") | ||
logger.setLevel("DEBUG") | ||
return logger.getChild(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from pathlib import Path | ||
from fastapi import FastAPI, WebSocket, Request | ||
from fastapi.templating import Jinja2Templates | ||
import asyncio | ||
|
||
from letta.settings import settings | ||
from installable_image import InstallableImage | ||
from installable_logger import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
target_file = settings.letta_dir / "logs" / "letta.log" | ||
|
||
app = FastAPI() | ||
|
||
|
||
async def log_reader(n=5): | ||
log_lines = [] | ||
with open(target_file, "r") as file: | ||
for line in file.readlines()[-n:]: | ||
if line is None: | ||
continue | ||
if line.__contains__("ERROR"): | ||
log_line = {"content": line, "color": "red"} | ||
elif line.__contains__("WARNING"): | ||
log_line = {"content": line, "color": "yellow"} | ||
else: | ||
log_line = {"content": line, "color": "green"} | ||
log_lines.append(log_line) | ||
return log_lines | ||
|
||
@app.websocket("/ws/log") | ||
async def websocket_endpoint_log(websocket: WebSocket): | ||
await websocket.accept() | ||
|
||
try: | ||
while True: | ||
await asyncio.sleep(1) | ||
logs = await log_reader(30) | ||
await websocket.send_json(logs) | ||
except Exception as e: | ||
logger.error(f"Error in log websocket: {e}") | ||
|
||
finally: | ||
await websocket.close() | ||
|
||
@app.get("/") | ||
async def get(request: Request): | ||
context = {"log_file": target_file, "icon": InstallableImage().get_icon_path()} | ||
templates = Jinja2Templates(directory=str((Path(__file__).parent / "templates").absolute())) | ||
return templates.TemplateResponse("index.html", {"request": request, "context": context}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en" class="dark"> | ||
<head> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<title>Letta Logs</title> | ||
<icon rel="icon" src="{{context.icon}}" /> | ||
</head> | ||
|
||
<body class="dark:bg-gray-900"> | ||
|
||
|
||
<div class="flex items-center py-2 px-3"> | ||
<h1 class="text-3xl text-slate-300">{{context.title}}</h1> | ||
</div> | ||
<br /> | ||
|
||
<div class="flex items-center py-2 px-3"> | ||
<i>Logs stored at | ||
<a href="file://{{context.log_file}}">{{context.log_file}}</a> | ||
</i> | ||
</div> | ||
|
||
<div class="flex items-center py-2 px-3"> | ||
<div | ||
id="logs" | ||
class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" | ||
> | ||
reading logs... | ||
</div> | ||
</div> | ||
|
||
<script> | ||
var ws_log = new WebSocket("ws://" + window.location.host + "/ws/log"); | ||
|
||
ws_log.onmessage = function (event) { | ||
var logs = document.getElementById("logs"); | ||
var log_data = JSON.parse(event.data); | ||
logs.innerHTML = ""; // Clear existing logs | ||
log_data.forEach(function (log) { | ||
var span = document.createElement("span"); | ||
span.classList.add("block"); | ||
span.style.color = log.color; | ||
span.innerHTML = log.content; | ||
logs.appendChild(span); | ||
}); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters