Bloque H4 — cache memory adapter routes prod warning through logger

`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) <noreply@anthropic.com>
master
dev 5 months ago
parent 0c15e0b94c
commit e40fc7fa1c

@ -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);

Loading…
Cancel
Save

Powered by TurnKey Linux.