2023-12-31 14:31:33 +01:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuLabel,
|
|
|
|
DropdownMenuRadioGroup,
|
|
|
|
DropdownMenuRadioItem,
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
2023-12-08 14:33:22 +01:00
|
|
|
import Heading from "@/components/ui/heading";
|
2023-12-31 14:31:33 +01:00
|
|
|
import copy from "copy-to-clipboard";
|
|
|
|
import { useCallback, useMemo, useState } from "react";
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
const logTypes = ["frigate", "go2rtc", "nginx"] as const;
|
|
|
|
type LogType = (typeof logTypes)[number];
|
2023-12-08 14:33:22 +01:00
|
|
|
|
|
|
|
function Logs() {
|
2023-12-31 14:31:33 +01:00
|
|
|
const [logService, setLogService] = useState<LogType>("frigate");
|
|
|
|
|
|
|
|
const { data: frigateLogs } = useSWR("logs/frigate", {
|
|
|
|
refreshInterval: 1000,
|
|
|
|
});
|
|
|
|
const { data: go2rtcLogs } = useSWR("logs/go2rtc", { refreshInterval: 1000 });
|
|
|
|
const { data: nginxLogs } = useSWR("logs/nginx", { refreshInterval: 1000 });
|
|
|
|
const logs = useMemo(() => {
|
|
|
|
if (logService == "frigate") {
|
|
|
|
return frigateLogs;
|
|
|
|
} else if (logService == "go2rtc") {
|
|
|
|
return go2rtcLogs;
|
|
|
|
} else if (logService == "nginx") {
|
|
|
|
return nginxLogs;
|
|
|
|
} else {
|
|
|
|
return "unknown logs";
|
|
|
|
}
|
|
|
|
}, [logService, frigateLogs, go2rtcLogs, nginxLogs]);
|
|
|
|
|
|
|
|
const handleCopyLogs = useCallback(() => {
|
|
|
|
copy(logs);
|
|
|
|
}, [logs]);
|
|
|
|
|
2023-12-08 14:33:22 +01:00
|
|
|
return (
|
2024-02-21 21:07:32 +01:00
|
|
|
<div className="relative w-full h-full overflow-hidden">
|
2023-12-31 14:31:33 +01:00
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<Heading className="first:mt-2" as="h2">
|
|
|
|
Logs
|
|
|
|
</Heading>
|
|
|
|
<div>
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
<Button className="mx-2 capitalize" variant="outline">
|
|
|
|
{logService} Logs
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuLabel>Select Logs To View</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuRadioGroup
|
|
|
|
value={logService}
|
|
|
|
onValueChange={(type) => setLogService(type as LogType)}
|
|
|
|
>
|
|
|
|
{Object.values(logTypes).map((item) => (
|
|
|
|
<DropdownMenuRadioItem
|
|
|
|
className="capitalize"
|
|
|
|
key={item}
|
|
|
|
value={item}
|
|
|
|
>
|
|
|
|
{item} Logs
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
))}
|
|
|
|
</DropdownMenuRadioGroup>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
|
|
|
<Button onClick={handleCopyLogs}>Copy to Clipboard</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-02-21 21:07:32 +01:00
|
|
|
<div className="absolute left-0 top-16 bottom-2 right-2 overflow-auto font-mono text-sm bg-secondary rounded p-2 whitespace-pre-wrap">
|
2023-12-31 14:31:33 +01:00
|
|
|
{logs}
|
|
|
|
</div>
|
2024-02-21 21:07:32 +01:00
|
|
|
</div>
|
2023-12-08 14:33:22 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Logs;
|