Files
2026-06-09 21:06:27 +01:00

3.5 KiB

name, description
name description
sp-api-capability-logger-memory Faithful in-memory CapabilityLoggerLike reference implementation (MemoryLogger) for the Suaveplan API capability system. Records every debug/info/warn/error call as a structured line on a shared sink, with child(bindings) merging parent + child bindings (child wins). The fixture that runLoggerConformance measures every logger implementation against.

@suaveplan/api-capability-logger-memory

Purpose

Faithful in-memory CapabilityLoggerLike reference implementation (MemoryLogger) for the Suaveplan API capability system. Records every debug/info/warn/error call as a structured line on a shared sink, with child(bindings) merging parent + child bindings (child wins) into descendant lines.

This is the fixture that @suaveplan/api-capability-kit's runLoggerConformance harness measures every logger implementation against. Its conformance test runs against both the direct implementation AND the same implementation behind @suaveplan/api-capability-proxy, proving the proxy stays transparent.

Architecture

Component Source Role
MemoryLogger src/memory-logger/memory-logger.ts In-memory CapabilityLoggerLike implementation
LogLevel src/memory-logger/memory-logger.ts Log level type
RecordedLine src/memory-logger/memory-logger.ts Recorded structured line type

File Structure

src/
  index.ts              # Exports MemoryLogger, LogLevel, RecordedLine
  memory-logger/
    memory-logger.ts    # Implementation
    memory-logger.md    # Module docs
    memory-logger.test.ts # Conformance + direct tests

Entry Points

Import Exports
@suaveplan/api-capability-logger-memory MemoryLogger, LogLevel, RecordedLine
@suaveplan/api-capability-logger-memory/memory-logger/memory-logger Same from feature subpath

Patterns

Basic logging

import { MemoryLogger } from "@suaveplan/api-capability-logger-memory";

const log = new MemoryLogger();
log.info("server started", { port: 8080 });
log.error("connection failed", { err: new Error("timeout") });

Child logger with merged bindings

const requestLog = log.child({ requestId: "req_123" });
requestLog.info("processing"); // includes { requestId: "req_123" }
const dbLog = requestLog.child({ db: "users" });
dbLog.info("query"); // includes { requestId: "req_123", db: "users" }

Inspecting recorded lines

// MemoryLogger exposes its recorded lines for test assertions
expect(log.lines).toHaveLength(2);
expect(log.lines[0].level).toBe("info");
expect(log.lines[0].message).toBe("server started");
expect(log.lines[0].bindings).toEqual({ port: 8080 });

Constraints

  • Reference implementation — the canonical in-memory logger; all other implementations measured against it.
  • Proxy transparency — conformance tests prove identical behaviour behind @suaveplan/api-capability-proxy.
  • Child wins on merge — when child(bindings) is called, child bindings override parent bindings with the same key.
  • Structured lines — every log call is recorded as a structured object with level, message, timestamp, and bindings.
  • Dependencies: @suaveplan/api-types, tslib. Dev: @suaveplan/api-capability-kit, @suaveplan/api-capability-proxy.

Checklist

  • Read src/memory-logger/memory-logger.ts before modifying logger behaviour
  • Preserve proxy transparency — changes must pass both direct and proxied conformance tests
  • Child binding merge semantics (child wins) must be preserved