Coder Social home page Coder Social logo

redacting-logger's Introduction

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
)

redacting-logger's People

Contributors

dependabot[bot] avatar grantbirki avatar nobe4 avatar shaeli avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.