feat(logs): add log level selection to tools ui (#3565)

This commit is contained in:
Meier Lukas
2025-07-17 10:43:13 +02:00
committed by GitHub
parent c00110e426
commit c4e5c3002b
12 changed files with 150 additions and 31 deletions

View File

@@ -1,22 +1,33 @@
import { observable } from "@trpc/server/observable";
import z from "zod";
import { logger } from "@homarr/log";
import { logLevels } from "@homarr/log/constants";
import type { LoggerMessage } from "@homarr/redis";
import { loggingChannel } from "@homarr/redis";
import { zodEnumFromArray } from "@homarr/validation/enums";
import { createTRPCRouter, permissionRequiredProcedure } from "../trpc";
export const logRouter = createTRPCRouter({
subscribe: permissionRequiredProcedure.requiresPermission("other-view-logs").subscription(() => {
return observable<LoggerMessage>((emit) => {
const unsubscribe = loggingChannel.subscribe((data) => {
emit.next(data);
});
logger.info("A tRPC client has connected to the logging procedure");
subscribe: permissionRequiredProcedure
.requiresPermission("other-view-logs")
.input(
z.object({
levels: z.array(zodEnumFromArray(logLevels)).default(["info"]),
}),
)
.subscription(({ input }) => {
return observable<LoggerMessage>((emit) => {
const unsubscribe = loggingChannel.subscribe((data) => {
if (!input.levels.includes(data.level)) return;
emit.next(data);
});
logger.info("A tRPC client has connected to the logging procedure");
return () => {
unsubscribe();
};
});
}),
return () => {
unsubscribe();
};
});
}),
});