You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
import {
|
|
LogLevel,
|
|
createCatalogDiagnostics,
|
|
type DiagnosticCatalog,
|
|
type DiagnosticEvent,
|
|
type Diagnostics,
|
|
type Logger
|
|
} from '$libs/logger';
|
|
import type { CacheKey } from '$libs/cache';
|
|
import {
|
|
CACHE_ACTIVE_DIAGNOSTIC_EVENTS,
|
|
CACHE_ACTIVE_LOG_MESSAGE_OPERATION_FAILED,
|
|
CACHE_MODULE
|
|
} from './consts.ts';
|
|
|
|
export type ActiveCacheDiagnosticType =
|
|
(typeof CACHE_ACTIVE_DIAGNOSTIC_EVENTS)[keyof typeof CACHE_ACTIVE_DIAGNOSTIC_EVENTS];
|
|
|
|
export interface ActiveCacheDiagnosticMeta {
|
|
readonly method: string;
|
|
readonly key?: CacheKey;
|
|
readonly error?: unknown;
|
|
}
|
|
|
|
export type ActiveCacheDiagnosticEvent = DiagnosticEvent<
|
|
ActiveCacheDiagnosticType,
|
|
ActiveCacheDiagnosticMeta
|
|
>;
|
|
export type ActiveCacheDiagnostics = Diagnostics<ActiveCacheDiagnosticEvent>;
|
|
|
|
const ACTIVE_CACHE_DIAGNOSTIC_LOGS: DiagnosticCatalog<ActiveCacheDiagnosticEvent> = {
|
|
[CACHE_ACTIVE_DIAGNOSTIC_EVENTS.OPERATION_FAILED]: {
|
|
level: LogLevel.WARN,
|
|
message: CACHE_ACTIVE_LOG_MESSAGE_OPERATION_FAILED
|
|
}
|
|
};
|
|
|
|
export function createActiveCacheDiagnostics(logger?: Logger): ActiveCacheDiagnostics {
|
|
return createCatalogDiagnostics({
|
|
logger,
|
|
defaultCategory: CACHE_MODULE,
|
|
catalog: ACTIVE_CACHE_DIAGNOSTIC_LOGS
|
|
});
|
|
}
|
|
|
|
export function emitActiveCacheDiagnostic(
|
|
diagnostics: ActiveCacheDiagnostics,
|
|
type: ActiveCacheDiagnosticType,
|
|
meta: ActiveCacheDiagnosticMeta
|
|
): void {
|
|
diagnostics.emit({
|
|
artifact: CACHE_MODULE,
|
|
type,
|
|
meta
|
|
});
|
|
}
|