guardian-risk-logger
v0.2.0
Published
Audit logging plugin for guardian-risk — logs reports and matched rules
Downloads
245
Maintainers
Readme
guardian-risk-logger
Requires:
guardian-risk(core)
npm install guardian-risk guardian-risk-loggerAudit logging for guardian-risk analysis results.
What gets logged
| Field | Source |
|-------|--------|
| score | report.score |
| riskLevel | report.level |
| matchedRules | Rule names from report.matchedRules |
| reasons | report.reasons |
| context | Sanitized request metadata (method, path, IP only) |
Production usage
import { Guardian } from 'guardian-risk';
import { loggerPlugin } from 'guardian-risk-logger';
const template = new Guardian()
.use(loggerPlugin({ level: 'info', minScore: 20 }))
.rule({ name: 'Bot', when: (s) => s.headlessUA === true, score: 30 });
// Middleware runs analyzeAsync → afterAnalyze logs automaticallySecurity notes
- Request headers are redacted from log context — only method, path, and validated IP are kept.
- Do not log raw cookies, auth tokens, or PII in custom sinks.
- Use
minScoreto reduce noise in high-traffic apps.
API
loggerPlugin(options)—afterAnalyzeauto-logginganalyzeAndLog(guardian, options)— one-shot analyze + loglogReport(report, options)— log an existing reportLogSink— custom destination (Datadog, CloudWatch, etc.)
See SECURITY.md.
