Module: Philiprehberger::LogFilter::Presets
- Defined in:
- lib/philiprehberger/log_filter/presets.rb
Overview
Factory methods that return pre-configured Filter instances for common log-noise scenarios.
Class Method Summary collapse
-
.assets ⇒ Filter
Filter that drops static-asset request log lines.
-
.bots ⇒ Filter
Filter that drops bot/crawler request log lines.
-
.health_check ⇒ Filter
Filter that drops health-check request log lines.
-
.pii ⇒ Filter
Filter that redacts common PII patterns from log lines.
-
.secrets ⇒ Filter
Filter that redacts common secret patterns from log lines.
Class Method Details
.assets ⇒ Filter
Filter that drops static-asset request log lines.
18 19 20 |
# File 'lib/philiprehberger/log_filter/presets.rb', line 18 def self.assets Filter.new.drop(/\.(css|js|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)\b/i) end |
.bots ⇒ Filter
Filter that drops bot/crawler request log lines.
25 26 27 |
# File 'lib/philiprehberger/log_filter/presets.rb', line 25 def self.bots Filter.new.drop(/bot|crawler|spider|slurp|googlebot|bingbot/i) end |
.health_check ⇒ Filter
Filter that drops health-check request log lines.
11 12 13 |
# File 'lib/philiprehberger/log_filter/presets.rb', line 11 def self.health_check Filter.new.drop(%r{health_?check|/health|/ping|/ready|/alive}i) end |
.pii ⇒ Filter
Filter that redacts common PII patterns from log lines.
Replaces email addresses, US Social Security Numbers, and 13–19 digit credit-card-shaped numbers with ‘[REDACTED]`.
35 36 37 38 39 40 |
# File 'lib/philiprehberger/log_filter/presets.rb', line 35 def self.pii Filter.new .replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i, '[REDACTED]') .replace(/\b\d{3}-\d{2}-\d{4}\b/, '[REDACTED]') .replace(/\b\d(?:[ -]?\d){12,18}\b/, '[REDACTED]') end |
.secrets ⇒ Filter
Filter that redacts common secret patterns from log lines.
Replaces Bearer tokens, ‘api_key=…`/`api-key=…` values, and AWS-style access key IDs with `[REDACTED]`.
48 49 50 51 52 53 |
# File 'lib/philiprehberger/log_filter/presets.rb', line 48 def self.secrets Filter.new .replace(/Bearer\s+[A-Za-z0-9._-]+/, 'Bearer [REDACTED]') .replace(/\b(api[_-]?key|access[_-]?token)=([A-Za-z0-9._-]+)/i, '\1=[REDACTED]') .replace(/\bAKIA[0-9A-Z]{16}\b/, '[REDACTED]') end |