1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-28 16:06:40 +01:00
Files
dozzle/assets/composable/logContext.ts
2024-10-04 13:47:12 -07:00

57 lines
1.3 KiB
TypeScript

import { Container } from "@/models/Container";
import { Level } from "@/models/LogEntry";
type LogContext = {
streamConfig: { stdout: boolean; stderr: boolean };
containers: Container[];
loadingMore: boolean;
hasComplexLogs: boolean;
levels: Set<Level>;
};
export const allLevels: Level[] = [
"info",
"debug",
"warn",
"error",
"fatal",
"trace",
"warning",
"critical",
"unknown",
];
// export for testing
export const loggingContextKey = Symbol("loggingContext") as InjectionKey<LogContext>;
const searchParams = new URLSearchParams(window.location.search);
const stdout = searchParams.has("stdout") ? searchParams.get("stdout") === "true" : true;
const stderr = searchParams.has("stderr") ? searchParams.get("stderr") === "true" : true;
export const provideLoggingContext = (containers: Ref<Container[]>) => {
provide(
loggingContextKey,
reactive({
streamConfig: { stdout, stderr },
containers,
loadingMore: false,
hasComplexLogs: false,
levels: new Set<Level>(allLevels),
}),
);
};
export const useLoggingContext = () => {
const context = inject(
loggingContextKey,
reactive({
streamConfig: { stdout: true, stderr: true },
containers: [],
loadingMore: false,
hasComplexLogs: false,
levels: new Set<Level>(allLevels),
}),
);
return toRefs(context);
};