@boring-stack-pkg/eslint-plugin-structured-logging
v0.1.2
Published
ESLint rules that enforce structured logging conventions: required event fields, masked PII in log payloads, and no stringified errors.
Downloads
2,281
Maintainers
Readme
eslint-plugin-structured-logging
ESLint rules that enforce structured-logging discipline:
require-event-field— every logger call carries a stableevent:identifier so log search isn't substring-matching.mask-pii-fields— emails, tokens, passwords, etc. must be masked before they hit the logger.no-error-stringify— neverString(error)/${error}/error.toString(); use a configured extractor (defaultgetErrorMessage) that preserves the cause chain.
All three rules treat any call to a name in loggerNames (default
logger, log, reqLogger, requestLogger) on a method in loggerMethods
(default fatal/error/warn/info/debug/trace) as a logger call.
Install
pnpm add -D @boring-stack-pkg/eslint-plugin-structured-loggingPeer deps: eslint >= 8.57, @typescript-eslint/parser >= 8,
typescript >= 5.
Use (flat config)
import tsParser from "@typescript-eslint/parser";
import structuredLogging from "@boring-stack-pkg/eslint-plugin-structured-logging";
export default [
{
files: ["**/*.{ts,tsx}"],
languageOptions: { parser: tsParser },
plugins: { "structured-logging": structuredLogging },
rules: {
"structured-logging/require-event-field": "error",
"structured-logging/mask-pii-fields": "error",
"structured-logging/no-error-stringify": "error",
},
},
];Or use the bundled config:
import structuredLogging from "@boring-stack-pkg/eslint-plugin-structured-logging";
export default [structuredLogging.configs.recommended];Rules
| Rule | Description | Fixable |
| ---------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------- |
| require-event-field | Require event: in logger payloads | – |
| mask-pii-fields | Disallow unmasked PII | – |
| no-error-stringify | Disallow String(error) / ${error} / error.toString() | yes (when extractor is imported) |
License
MIT.
