From e40fc7fa1c370365932eac1fe2c841a8a4c572b8 Mon Sep 17 00:00:00 2001 From: dev Date: Tue, 5 May 2026 03:03:39 +0200 Subject: [PATCH] =?UTF-8?q?Bloque=20H4=20=E2=80=94=20cache=20memory=20adap?= =?UTF-8?q?ter=20routes=20prod=20warning=20through=20logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `MemoryCacheAdapterOptions.logger?: Logger` lets the adapter's production warning flow through the framework's logger (and from there, every transport the host has wired) instead of always landing on `console.warn`. Resolution order: 1. `onProductionWarning?` callback (caller has full control) 2. `logger?.warn(CACHE_MODULE, message)` (framework path, picks up Sentry/Datadog/Loki/whatever the host uses) 3. `console.warn` (legacy fallback, kept for callers that do not wire either of the above) No behavior change for existing apps — the new option is opt-in. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/libs/cache/adapters/memory.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/libs/cache/adapters/memory.ts b/src/libs/cache/adapters/memory.ts index 00fc3d8..8fb4c4e 100644 --- a/src/libs/cache/adapters/memory.ts +++ b/src/libs/cache/adapters/memory.ts @@ -5,9 +5,11 @@ import { CACHE_MEMORY_EVICT_DELETE, CACHE_MEMORY_EVICT_EXPIRED, CACHE_MEMORY_EVICT_MAX_ENTRIES, - CACHE_MEMORY_EVICT_MAX_SIZE_BYTES + CACHE_MEMORY_EVICT_MAX_SIZE_BYTES, + CACHE_MODULE } from '../consts.ts'; import { isProduction } from '$libs/env'; +import type { Logger } from '$libs/logger'; import type { CacheAdapter, CacheAdapterSetOptions, @@ -24,7 +26,19 @@ export type MemoryCacheAdapterOptions = { onEvict?: (event: { key: string; reason: MemoryCacheEvictReason }) => void; production?: boolean; suppressProductionWarning?: boolean; + /** + * Custom production-warning sink. Called once with the warning + * message instead of `console.warn`. Takes precedence over `logger`. + */ onProductionWarning?: (message: string) => void; + /** + * Route the production warning through a `$libs/logger.Logger` + * (`logger.warn(category, message)`) instead of writing to + * `console.warn`. The framework's hosts wire this from `App.Logger` + * so the warning lands in the same transports as the rest of the + * runtime's diagnostics. + */ + logger?: Logger; }; type MemoryEntry = { @@ -210,6 +224,13 @@ function warnIfProduction(options: MemoryCacheAdapterOptions): void { options.onProductionWarning(CACHE_MEMORY_ADAPTER_PRODUCTION_WARNING); return; } + if (options.logger !== undefined) { + // Route through the framework's logger so the warning reaches + // every transport the host has configured (Sentry, Datadog, + // console, etc.) instead of always landing on `console.warn`. + options.logger.warn(CACHE_MODULE, CACHE_MEMORY_ADAPTER_PRODUCTION_WARNING); + return; + } if (defaultProductionWarningEmitted) return; defaultProductionWarningEmitted = true; console.warn(CACHE_MEMORY_ADAPTER_PRODUCTION_WARNING);