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>
35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
import js from '@eslint/js';
|
|
import tseslint from 'typescript-eslint';
|
|
import stylistic from '@stylistic/eslint-plugin';
|
|
|
|
export default tseslint.config(
|
|
{ ignores: ['dist', 'node_modules', 'bench', 'coverage'] },
|
|
js.configs.recommended,
|
|
...tseslint.configs.recommended,
|
|
{
|
|
plugins: { '@stylistic': stylistic },
|
|
rules: {
|
|
// The request pipeline accumulates a dynamic context object by design;
|
|
// `any` there is load-bearing, not laziness. Flag it as a warning so new
|
|
// uses are visible without failing the build.
|
|
'@typescript-eslint/no-explicit-any': 'warn',
|
|
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
|
// Breathing room around multi-line blocks (for/while/if/function/class) so
|
|
// consecutive blocks don't read as one wall of code. Auto-fixable.
|
|
'@stylistic/padding-line-between-statements': [
|
|
'error',
|
|
{ blankLine: 'always', prev: 'multiline-block-like', next: '*' },
|
|
{ blankLine: 'always', prev: '*', next: 'multiline-block-like' },
|
|
],
|
|
},
|
|
},
|
|
{
|
|
// 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' },
|
|
},
|
|
);
|