@sincpro/client-framework 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -217,8 +217,10 @@ options)`: no route, no verb, no RPC method. The contract's bindings (`rest`, `r
217
217
  - **The application layer imports no logger.** A bounded context has `projectBoundedContext.logger`; a run
218
218
  hands `this.logger`, bound to its execution. Only `logger` (infrastructure, the global one) and
219
219
  `loggerAdapter` are predefined; injected as a dependency they bind to the run (`BIND`), imported
220
- at module level they do not. No logger is predefined for an application layer. Console is the
221
- default engine; `configureProcess({ logger })` and `configureLogger(...)` take the same
220
+ at module level they do not. No logger is predefined for an application layer. Which INFO and
221
+ DEBUG lines speak is a `LogFilter` (level, layer, bounded context — `speaks`), the same rule
222
+ for the console and any sink (`filteredLogger`); WARN and ERROR always speak, and spans are
223
+ never filtered. Console is the default engine; `configureProcess({ logger })` and `configureLogger(...)` take the same
222
224
  `LoggerConfiguration`. The host chooses production explicitly. Never log DTOs, results or the
223
225
  full session context automatically.
224
226
  - **A failure is described once, as sincpro_framework's failure line** (`PRD_03 §6`,
package/README.md CHANGED
@@ -568,6 +568,19 @@ configureLogger({ mode: "development", level: "info", layers: { adapter: false }
568
568
  configureLogger({ mode: "production" }); // the console, silent
569
569
  configureLogger({ engine: combineLoggers(consoleLogger({ mode }), lokiLogger) }); // other sinks
570
570
  configureLogger({ engine: false }); // no logs
571
+
572
+ // Which INFO and DEBUG lines speak — by level, layer and bounded context; WARN and ERROR always.
573
+ // Spans are never filtered: a quiet line still has its span.
574
+ const production = {
575
+ level: "info",
576
+ layers: { adapter: false },
577
+ boundedContexts: { common: false },
578
+ };
579
+ configureLogger({
580
+ engine: filteredLogger(combineLoggers(consoleSink, lokiSink), () =>
581
+ debugging ? {} : production,
582
+ ),
583
+ });
571
584
  ```
572
585
 
573
586
  The console is the default engine. In production it is silent; in development it prints
@@ -1,8 +1,6 @@
1
- import type { Logger, LogLayer, LogLevel } from "../domain/logging.js";
2
- export type ConsoleLoggerOptions = {
3
- mode: "development" | "production";
4
- /** Development INFO/DEBUG threshold. WARN/ERROR are never hidden by layer/level masks. */
5
- level?: LogLevel;
6
- layers?: Partial<Record<LogLayer, boolean>>;
1
+ import { type LogFilter, type Logger } from "../domain/logging.js";
2
+ /** The console's mode, and which INFO and DEBUG lines it prints (`LogFilter`). */
3
+ export type ConsoleLoggerOptions = LogFilter & {
4
+ readonly mode: "development" | "production";
7
5
  };
8
6
  export declare function consoleLogger(options: ConsoleLoggerOptions): Logger;
@@ -1,4 +1,4 @@
1
- const RANK = { debug: 0, info: 1, warn: 2, error: 3 };
1
+ import { isLogLevel, speaks, } from "../domain/logging.js";
2
2
  /**
3
3
  * Built-in console engine: silent in production, configurable
4
4
  * development layers, and WARN/ERROR preserved. Other sinks are filtered independently.
@@ -15,19 +15,18 @@ export function consoleLogger(options) {
15
15
  if (mode !== "development" && mode !== "production") {
16
16
  throw new TypeError("Console logger mode must be development or production");
17
17
  }
18
- const level = options.level ?? "debug";
19
- if (!Object.hasOwn(RANK, level)) {
18
+ if (options.level !== undefined && !isLogLevel(options.level)) {
20
19
  throw new TypeError("Console logger level must be debug, info, warn or error");
21
20
  }
22
- const layers = { ...options.layers };
21
+ const filter = {
22
+ level: options.level ?? "debug",
23
+ layers: { ...options.layers },
24
+ boundedContexts: { ...options.boundedContexts },
25
+ };
23
26
  return {
24
27
  log(record) {
25
- if (mode === "production")
28
+ if (mode === "production" || !speaks(record, filter))
26
29
  return;
27
- if (record.level !== "warn" && record.level !== "error") {
28
- if (layers[record.layer] === false || RANK[record.level] < RANK[level])
29
- return;
30
- }
31
30
  const prefix = `${record.timestamp} [${record.layer}] ${record.level.toUpperCase()}`;
32
31
  const method = record.level === "debug"
33
32
  ? console.debug
@@ -71,3 +71,30 @@ export interface LayerLogger {
71
71
  warn(message: string, attributes?: Attributes): void;
72
72
  error(message: string, attributes?: Attributes): void;
73
73
  }
74
+ /**
75
+ * Which INFO and DEBUG lines speak — by level, by layer and by bounded context. WARN and ERROR
76
+ * always do: a failure is never silenced. What a filter does not name speaks.
77
+ *
78
+ * { level: "info", layers: { adapter: false }, boundedContexts: { common: false } }
79
+ *
80
+ * Context: only lines are filtered, never spans — a quiet line still has its span, so a trace
81
+ * shows every run. A line outside a run (the infrastructure's `logger`) has no bounded context
82
+ * and is filtered by its layer alone.
83
+ */
84
+ export type LogFilter = {
85
+ /** The lowest level of INFO and DEBUG that speaks (`debug`: every one). */
86
+ readonly level?: LogLevel;
87
+ /** By layer: `false` keeps a layer's INFO and DEBUG quiet. */
88
+ readonly layers?: Readonly<Partial<Record<LogLayer, boolean>>>;
89
+ /** By bounded context's name: `false` keeps its INFO and DEBUG quiet. */
90
+ readonly boundedContexts?: Readonly<Record<string, boolean>>;
91
+ };
92
+ /** Whether `level` is one a line can have. */
93
+ export declare function isLogLevel(level: unknown): level is LogLevel;
94
+ /**
95
+ * Whether `record` speaks under `filter`:
96
+ * 1. WARN and ERROR, always.
97
+ * 2. INFO and DEBUG at the filter's level or above, from a layer and a bounded context it does
98
+ * not keep quiet.
99
+ */
100
+ export declare function speaks(record: LogRecord, filter: LogFilter): boolean;
@@ -1 +1,21 @@
1
- export {};
1
+ const RANK = { debug: 0, info: 1, warn: 2, error: 3 };
2
+ /** Whether `level` is one a line can have. */
3
+ export function isLogLevel(level) {
4
+ return typeof level === "string" && Object.hasOwn(RANK, level);
5
+ }
6
+ /**
7
+ * Whether `record` speaks under `filter`:
8
+ * 1. WARN and ERROR, always.
9
+ * 2. INFO and DEBUG at the filter's level or above, from a layer and a bounded context it does
10
+ * not keep quiet.
11
+ */
12
+ export function speaks(record, filter) {
13
+ if (record.level === "warn" || record.level === "error")
14
+ return true;
15
+ if (RANK[record.level] < RANK[filter.level ?? "debug"])
16
+ return false;
17
+ if (filter.layers?.[record.layer] === false)
18
+ return false;
19
+ const boundedContext = record.boundedContext;
20
+ return !(boundedContext !== undefined && filter.boundedContexts?.[boundedContext] === false);
21
+ }
@@ -10,9 +10,9 @@
10
10
  */
11
11
  export type { ErrorAbout, ErrorReporter, } from "./domain/errors.js";
12
12
  export { type IdentityKeys, identityOf, type ProcessIdentity, RELEASE, TENANT, tenantOf, USER_ID, userOf, } from "./domain/identity.js";
13
- export type { FailureDescription, LayerLogger, Logger, LogLayer, LogLevel, LogRecord, } from "./domain/logging.js";
13
+ export { type FailureDescription, isLogLevel, type LayerLogger, type LogFilter, type Logger, type LogLayer, type LogLevel, type LogRecord, speaks, } from "./domain/logging.js";
14
14
  export { type Attributes, NO_TRACER, type Outcome, type Span, type Tracer, } from "./domain/tracing.js";
15
15
  export { describeFailure } from "./services/failure.js";
16
- export { combineLoggers, logger, loggerAdapter, } from "./services/logging.js";
16
+ export { combineLoggers, filteredLogger, logger, loggerAdapter, } from "./services/logging.js";
17
17
  export { outcomeOf } from "./services/outcome.js";
18
18
  export { reportError } from "./services/reporting.js";
@@ -1,6 +1,7 @@
1
1
  export { identityOf, RELEASE, TENANT, tenantOf, USER_ID, userOf, } from "./domain/identity.js";
2
+ export { isLogLevel, speaks, } from "./domain/logging.js";
2
3
  export { NO_TRACER, } from "./domain/tracing.js";
3
4
  export { describeFailure } from "./services/failure.js";
4
- export { combineLoggers, logger, loggerAdapter, } from "./services/logging.js";
5
+ export { combineLoggers, filteredLogger, logger, loggerAdapter, } from "./services/logging.js";
5
6
  export { outcomeOf } from "./services/outcome.js";
6
7
  export { reportError } from "./services/reporting.js";
@@ -1,5 +1,5 @@
1
1
  import { type Execution } from "../../context/domain/execution.js";
2
- import type { FailureDescription, LayerLogger, Logger, LogLayer } from "../domain/logging.js";
2
+ import { type FailureDescription, type LayerLogger, type LogFilter, type Logger, type LogLayer } from "../domain/logging.js";
3
3
  import type { Outcome } from "../domain/tracing.js";
4
4
  /** The infrastructure's logger — the global one: the code that starts and holds the application. */
5
5
  export declare const logger: LayerLogger;
@@ -11,6 +11,13 @@ export declare function boundedContextLogger(name: string): LayerLogger;
11
11
  type RunLogLayer = Extract<LogLayer, "feature" | "application_service" | "event_handler">;
12
12
  /** @internal — what a Feature or ApplicationService finds as `this.logger` while it runs. */
13
13
  export declare function executionLogger(layer: RunLogLayer, execution: Execution): LayerLogger;
14
+ /**
15
+ * `engine`, hearing only the lines `filter` lets speak — WARN and ERROR always (`speaks`). A
16
+ * function is read on every line, so a debug switch changes what speaks without rebuilding:
17
+ *
18
+ * filteredLogger(combineLoggers(console, loki), () => (debugging ? everything : production))
19
+ */
20
+ export declare function filteredLogger(engine: Logger, filter: LogFilter | (() => LogFilter)): Logger;
14
21
  /** Each destination keeps its own policy; one failing sink does not hold back the others. */
15
22
  export declare function combineLoggers(...loggers: readonly Logger[]): Logger;
16
23
  /** @internal — lifecycle records contain correlation and outcome, never business payloads. */
@@ -1,5 +1,6 @@
1
1
  import { BIND } from "../../context/domain/execution.js";
2
2
  import { tenantOf, userOf } from "../domain/identity.js";
3
+ import { speaks, } from "../domain/logging.js";
3
4
  import { observabilityNow } from "../infrastructure/registry.js";
4
5
  const processSink = () => observabilityNow().logger;
5
6
  /** Sink failures cannot replace a business outcome or cause unhandled async rejections. */
@@ -77,6 +78,21 @@ export function boundedContextLogger(name) {
77
78
  export function executionLogger(layer, execution) {
78
79
  return layerLogger(layer, processSink, correlationOf(execution));
79
80
  }
81
+ /**
82
+ * `engine`, hearing only the lines `filter` lets speak — WARN and ERROR always (`speaks`). A
83
+ * function is read on every line, so a debug switch changes what speaks without rebuilding:
84
+ *
85
+ * filteredLogger(combineLoggers(console, loki), () => (debugging ? everything : production))
86
+ */
87
+ export function filteredLogger(engine, filter) {
88
+ const current = typeof filter === "function" ? filter : () => filter;
89
+ return {
90
+ log: (record) => {
91
+ if (speaks(record, current()))
92
+ deliver(engine, record);
93
+ },
94
+ };
95
+ }
80
96
  /** Each destination keeps its own policy; one failing sink does not hold back the others. */
81
97
  export function combineLoggers(...loggers) {
82
98
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/client-framework",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "The client side of sincpro_framework, for every platform: Feature and ApplicationService traced and reported by default, applications made of domains, and the typed client generated from a service's contract. No React, no DOM.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",