redacting-logger
A redacting Ruby logger to prevent the leaking of secrets via logs
This Gem wraps the official Ruby logger
utility
Installation 💎
You can download this Gem from GitHub Packages or RubyGems
Via a Gemfile:
source "https://rubygems.org"
gem "redacting-logger", "~> X.X.X"
Usage 💻
Basic
require "redacting_logger"
logger = RedactingLogger.new(redact_patterns: [/topsecret/])
logger.info("This is a topsecret message.")
This will output:
I, [timestamp] INFO -- : This is a [REDACTED] message.
Advanced
require "redacting_logger"
logger = RedactingLogger.new(
$stdout,
redact_patterns: [/REDACTED_PATTERN1/, /REDACTED_PATTERN2/],
level: Logger::INFO,
redacted_msg: "[REDACTED]",
use_default_patterns: true
)
logger.info("This is a message with a REDACTED_PATTERN1 and REDACTED_PATTERN2 in it.")
This will output:
I, [timestamp] INFO -- : This is a message with a [REDACTED] and [REDACTED] in it.
Default Redaction Patterns
This Gem comes pre-built with a few redaction patterns to help you get started. These patterns can be located in lib/patterns/default.rb
A few examples of these patterns are:
- GitHub Personal Access Tokens
- GitHub Temporary Actions Tokens
- RSA Private Keys
- JWT Tokens
You can disable these default patterns with:
logger = RedactingLogger.new(
use_default_patterns: false
)