Logs
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import testAuth from "../auth";
|
||||||
|
import { StatusCodes } from "http-status-codes";
|
||||||
|
import { getAllContainerLogs } from "@/core/server/docker";
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||||
|
const auth = await testAuth(req);
|
||||||
|
|
||||||
|
if (auth) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ message: auth },
|
||||||
|
{ status: StatusCodes.UNAUTHORIZED }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(await getAllContainerLogs());
|
||||||
|
}
|
||||||
+26
-4
@@ -19,7 +19,7 @@ export default function LogsPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
setLogs(await getAllContainerLogs());
|
if (!isPaused) setLogs(await getAllContainerLogs());
|
||||||
};
|
};
|
||||||
|
|
||||||
const iid = setInterval(fetch, 1000);
|
const iid = setInterval(fetch, 1000);
|
||||||
@@ -33,6 +33,26 @@ export default function LogsPage() {
|
|||||||
filter === "all" ? true : log.level === filter
|
filter === "all" ? true : log.level === filter
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleExport = () => {
|
||||||
|
// Convert data to JSON string
|
||||||
|
const json = JSON.stringify(filteredLogs, null, 2);
|
||||||
|
|
||||||
|
// Create a blob from the JSON
|
||||||
|
const blob = new Blob([json], { type: "application/json" });
|
||||||
|
|
||||||
|
// Create a temporary URL for the blob
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
// Create a temporary link and click it
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.download = "logs.json"; // File name
|
||||||
|
link.click();
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
const getLevelClass = (level: string) => {
|
const getLevelClass = (level: string) => {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case "info":
|
case "info":
|
||||||
@@ -90,13 +110,15 @@ export default function LogsPage() {
|
|||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<Button variant="outline" size="sm" className="gap-2">
|
{/* <Button variant="outline" size="sm" className="gap-2">
|
||||||
<Filter className="w-4 h-4" />
|
<Filter className="w-4 h-4" />
|
||||||
<span className="hidden sm:inline">Advanced Filter</span>
|
<span className="hidden sm:inline">Advanced Filter</span>
|
||||||
</Button>
|
</Button> */}
|
||||||
<Button variant="outline" size="sm" className="gap-2">
|
<Button variant="outline" size="sm" className="gap-2">
|
||||||
<Download className="w-4 h-4" />
|
<Download className="w-4 h-4" />
|
||||||
<span className="hidden sm:inline">Export</span>
|
<span className="hidden sm:inline" onClick={handleExport}>
|
||||||
|
Export
|
||||||
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<div className="hidden md:block w-px h-6 bg-border" />
|
<div className="hidden md:block w-px h-6 bg-border" />
|
||||||
|
|||||||
Reference in New Issue
Block a user