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

+8
View File
@@ -23,4 +23,12 @@ export default tseslint.config(
],
},
},
{
// Nothing in core writes to console directly — every diagnostic goes through the injectable
// `Logger`, or an application cannot redirect it. This is the rule form of a check that was
// otherwise a `grep` somebody has to remember to run.
files: ['src/**/*.ts'],
ignores: ['src/logger.ts'], // the default logger *is* the console sink; that is its whole job
rules: { 'no-console': 'error' },
},
);