feat: retain application log history
This commit is contained in:
1 parent
a2219b72f6
commit
ce61c87cd8
12 files changed
+396
-51
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import type { LogLevel } from "@homarr/core/infrastructure/logs/constants";
|
||||
import { parse } from "superjson";
|
||||
|
||||
import type { LoggerMessage } from "@homarr/core/infrastructure/logs/constants";
|
||||
import { LOG_HISTORY_KEY, LOG_HISTORY_MAX_ENTRIES } from "@homarr/core/infrastructure/logs/constants";
|
||||
|
||||
import { createListChannel, createSubPubChannel } from "./lib/channel";
|
||||
import { createRedisConnection } from "./lib/connection";
|
||||
|
||||
export {
|
||||
handshakeAsync,
|
||||
@@ -15,9 +19,16 @@ export const pingChannel = createSubPubChannel<
|
||||
>("ping");
|
||||
export const pingUrlChannel = createListChannel<string>("ping-url");
|
||||
|
||||
export interface LoggerMessage {
|
||||
message: string;
|
||||
level: LogLevel;
|
||||
}
|
||||
export type { LoggerMessage } from "@homarr/core/infrastructure/logs/constants";
|
||||
|
||||
export const loggingChannel = createSubPubChannel<LoggerMessage>("logging");
|
||||
const liveLoggingChannel = createSubPubChannel<LoggerMessage>("logging", { persist: false });
|
||||
const loggingHistoryClient = createRedisConnection();
|
||||
|
||||
export const loggingChannel = {
|
||||
subscribe: liveLoggingChannel.subscribe,
|
||||
subscribeAsync: liveLoggingChannel.subscribeAsync,
|
||||
getRecentAsync: async () => {
|
||||
const messages = await loggingHistoryClient.lrange(LOG_HISTORY_KEY, 0, LOG_HISTORY_MAX_ENTRIES - 1);
|
||||
return messages.map((message) => parse<LoggerMessage>(message)).toReversed();
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user