No description
  • Ruby 83.7%
  • Shell 16.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
nobe4 490f21bf26
Merge pull request #154 from github/nobe4-patch-1
fix(CODEOWNERS): use the correct team
2026-06-11 15:32:09 +02:00
.bundle use modern bootstrap and bundle config 2025-03-18 12:44:01 -07:00
.github fix(CODEOWNERS): use the correct team 2026-06-11 15:12:10 +02:00
docs/assets update docs 2023-11-13 14:19:29 -07:00
lib Bump version to 1.5.2 2026-05-26 15:37:19 -07:00
script use the latest ruby version and update ci jobs to match modern scripts 2025-03-18 12:47:13 -07:00
spec Add test coverage for ghs_ token edge cases 2026-05-27 10:59:18 -07:00
vendor/cache Merge branch 'main' into dependabot/bundler/bundler-92edaf4459 2025-10-29 08:46:02 -07:00
.gitignore use modern bootstrap and bundle config 2025-03-18 12:44:01 -07:00
.rubocop.yml init 2023-11-13 12:44:33 -07:00
.ruby-version use the latest ruby version and update ci jobs to match modern scripts 2025-03-18 12:47:13 -07:00
Gemfile Bump the ruby-dependencies group across 1 directory with 3 updates 2025-10-29 15:42:05 +00:00
Gemfile.lock Merge branch 'main' into dependabot/bundler/bundler-92edaf4459 2025-10-29 08:46:02 -07:00
LICENSE Initial commit 2023-11-13 12:30:00 -07:00
README.md update docs 2023-11-22 09:40:47 -07:00
redacting-logger.gemspec update gemspec 2023-11-22 09:39:01 -07:00

redacting-logger

test lint build CodeQL release

A redacting Ruby logger to prevent the leaking of secrets via logs

This Gem wraps the official Ruby logger utility

Gem

Installation 💎

You can download this Gem from GitHub Packages or RubyGems

Via a Gemfile:

source "https://rubygems.org"

gem "redacting-logger", "~> X.X.X" # Replace X.X.X with the latest version

Usage 💻

Basic

require "redacting_logger"

# Create a new logger
logger = RedactingLogger.new(redact_patterns: [/topsecret/])

# Log a message that contains some redacted pattern
logger.info("This is a topsecret message.")

This will output:

I, [timestamp]  INFO -- : This is a [REDACTED] message.

Advanced

require "redacting_logger"

# Create a new logger
logger = RedactingLogger.new(
  $stdout, # The device to log to (defaults to $stdout if not provided)
  redact_patterns: [/REDACTED_PATTERN1/, /REDACTED_PATTERN2/], # An array of Regexp patterns to redact from the logs
  level: Logger::INFO, # The log level to use
  redacted_msg: "[REDACTED]", # The message to replace the redacted patterns with
  use_default_patterns: true # Whether to use the default built-in patterns or not
)

# Log a message that contains some redacted patterns
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 # Whether to use the default built-in patterns or not
)