registry
@automindzsheets 01–77shadcn 4.x
SHEET 65

JSON Logger (TypeScript)

item / server / observability

JSON-lines logger with key-suffix secret redaction, an injectable sink, and child loggers for request-scoped fields.

type
item
files
2
registry deps
none
npm deps
none
env vars
LOG_LEVEL

installs

  • ~/lib/automindz/log-json.ts
  • ~/tests/log-json.test.mts
  • Injectable sink and env, so the shipped test never touches stdout
  • Same redaction rule and key order as the Python twin
  • An explicit level beats LOG_LEVEL; an unknown LOG_LEVEL falls back to info

const log = createLogger({ service: "acme-api" }), then log.info("job done", { runId }) or log.error("failed", { runId }, err); log.child({ requestId }) bakes fields into every line. One JSON object per line: ts, level, service, msg, your fields, then err with type, message, stack. Keys ending in key, secret, token, password, authorization or cookie (or equal to auth) are replaced with [redacted] before serialisation, recursively; extend log.redactSuffixes for app-specific names. LOG_LEVEL is read from the env option (default process.env) when the logger is created. Circular and non-plain values are stringified, never thrown. Run the shipped test with node --test tests/log-json.test.mts.

Variations

one state per section

No previews for this item yet.