feat(observability): an injectable logger, and a lint rule that keeps core off console

Task 4. createApp({ logger }) accepts any Logger; the default writes structured
JSON, or a readable line on a TTY, decided once at construction rather than per
record. It writes through console, which is what lets core have a logging
contract while reflect-metadata stays the only runtime dependency.

Four levels, because four have callers. Core's diagnostics were all warn — every
one of the eight console.warn calls — and request logging adds info and error.
No trace, no fatal: a level nothing emits is a decision handed to the user for
no reason.

Registered rather than declared as a provider. Provider boot failures are
reported while the graph is still resolving and shutdown warnings after it is
gone, so a logger that lives in the graph cannot cover either end. It is also
registered as a builtin provider, so @needs('logger') reaches the same object —
one instance, two access paths — and exposed on App so serveDeno/serveBun report
through the application's logger instead of past it.

The [green-tea] prefix moves out of the prose into a `name` field: an aggregator
filters on a field and cannot filter on a substring of a sentence. Context that
was interpolated into messages is now structured alongside them.

#10 asks that nothing in core call console directly. That is now a lint rule
scoped to src/ rather than a grep somebody has to remember, with src/logger.ts
exempted because being the console sink is its entire job. Verified it fails on
a planted console.log.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-08-16 14:51:33 -05:00
1 parent 7b0a3d4e24
commit df460f01dd
8 files changed
+316 -26

No files matched your search

+5
View File
@@ -58,6 +58,7 @@ export {
// Bus & flow
export { Bus } from './bus';
export type { LifecycleEvent, EventPayload, Correlation } from './bus';
export { flow, Flow } from './flow';
export type { StepFn, CompiledFlow } from './flow';
@@ -65,6 +66,10 @@ export type { StepFn, CompiledFlow } from './flow';
export { needs, ctx, param, query, body, headers, header, inbound, abort } from './params';
export type { Query, Headers, Context, ArgSpec, ArgDecorator } from './params';
// Observability
export { createDefaultLogger } from './logger';
export type { Logger, LogLevel, LogFields } from './logger';
// Streaming
export { channel, isAsyncIterable } from './channel';
export type { Channel } from './channel';