Skip to content

refactor: one silent fallback logger in lib/log - #261

Closed
diegolmello wants to merge 2 commits into
mobilefrom
arch/07
Closed

refactor: one silent fallback logger in lib/log#261
diegolmello wants to merge 2 commits into
mobilefrom
arch/07

Conversation

@diegolmello

@diegolmello diegolmello commented Aug 12, 2026

Copy link
Copy Markdown
Member

Proposed changes

lib/log.ts held two separate implementations of a logger that writes nothing: the InternalLog class, instantiated once to be the initial value, and an object literal that silence() rebuilt on every call. They had already drifted — one returned undefined and routed the legacy warn through warning, the other returned null and gave warn its own empty body. Both were invisible, because neither wrote anything.

There is now one value. silentLogger is the initial value of logger and is what silence() installs. InternalLog is deleted. The module's public surface is unchanged — logger, replaceLog and silence, with the signatures they already had — so nothing that imports it has to change.

Judgement calls, recorded in ADR-0005:

  • The fallback logger stays silent. Making it write to the console would put Driver errors from recovered paths — a failed unsubscribe, a Reopen about to be retried — into the terminal of a host app that never asked for them, with no way to turn them off short of importing this module. The supported way to see that output already exists: pass a logger to the Client, or call replaceLog.
  • silentLogger is not exported. The suite already has its own recording logger for Sockets and Drivers, so nothing outside the module needs the value, and a second exported logger by that name would be easy to import in place of that one by mistake.
  • replaceLog still offers no way back to the previous logger. silence() returns to the fallback, not to whatever was installed before. No caller needs more, so no new surface was added for it.

One behaviour change worth naming: silence() used to install a fresh object each call and now installs the shared fallback, so mutating a method on logger after silence() would affect every later fallback rather than one. The initial value was already a single shared instance, so this narrows an existing hazard rather than adding one.

Fallback logger is added to CONTEXT.md — the concept was load-bearing across the Socket and Driver constructors but had no name.

lib/emitter.ts was reviewed in the same pass and deliberately left alone. Its two overrides are already covered by ADR-0002 and pinned exhaustively by its spec; the only change worth making there — collapsing off's two lookups into the one predicate removeAllListeners already uses — is behaviour-identical and would need the ADR reworded for no gain.

No pinning test changed. The Driver suite is untouched, and this module had no spec before.

Steps to reproduce

  • npm run lint
  • npm run typecheck
  • npm test

Tests

  • lib/__tests__/log.spec.ts — new spec for the module, which had none:
    • the fallback logger answers every level the ILogger contract names, including the legacy warn
    • the fallback logger writes nothing to any console method
    • replaceLog is seen by everything that reads logger afterwards
    • silence undoes a replacement, back to the same fallback the SDK started with

@diegolmello diegolmello changed the title refactor: one silent fallback logger instead of three refactor: one silent fallback logger in lib/log Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant