Giter Club home page Giter Club logo

activejob-filtering's Introduction

Activejob::Filtering

This is an ActiveJob extension that allows to filter arguments in ActiveJob's log output.

Version: 0.1.0. Tested on ruby 3.0.1, rails: ~> 7.0.5, activejob: 7.0.5.

If you using Rails >= 6.1

Rails >= 6.1 has the same features as this gem. In Rails you can disable log arguments to output like followings:

class SensitiveJob < ApplicationJob
  self.log_arguments = false

  def perform(args)
  end
end

See PR: rails/rails#37660

And PR: https://github.com/springerigor/rails/commit/02084de54d4b6c0c5861b33019a8f550b1e1ac84

Installation

Add this line to your application's Gemfile:

gem 'activejob-filtering', '0.1.0', github: 'pinifloyd/activejob-filtering'

And then execute:

$ bundle install

Usage

Create file config/initializers/activejob_filtering.rb (you can skip this step as bellow you can see settings by default).

ActiveJob::Filtering::Config.configure do |c|
  # Hide all arguments on any job. Same as a new feature log_arguments = false
  # in Rails >= 6.1. If false then gem will try to mask args if it possible
  # => [FILTERED].
  c.hide_arguments = false

  # Hash key where gem can find settings for any job.
  c.settings_key = :active_job

  # :nodoc
  c.filter_class = ActiveSupport::ParameterFilter

  # :nodoc
  c.filter_fields = Rails.application.config.filter_parameters
end

Define your job:

class MyJob < ApplicationJob
  def perform(*args)
  end
end

And call defined job like followings:

MyJob.perform_later(password: 'my-password', login: 'my-login')

Output example:

[ActiveJob] [MyJob] [ae3421c0-dcc7-4c3b-a741-ba06d8d68bf3] Performing MyJob (Job ID: ae3421c0-dcc7-4c3b-a741-ba06d8d68bf3) from Inline(default) enqueued at 2023-07-05T13:41:31Z WITH ARGS: {:password=>\"[FILTERED]\", :param_one=>\"some-param\"}

IMPORTANT THING: gem works only with hash based args.

Invalid format:

MyJob.perform_later('my-password', 'my-login')

Output example:

[ActiveJob] [MyJob] [e9bb4ca4-a1bb-4b03-a6e8-b67fb869c5d4] Performing MyJob (Job ID: e9bb4ca4-a1bb-4b03-a6e8-b67fb869c5d4) from Inline(default) enqueued at 2023-07-05T14:04:16Z [ERROR: WRONG FORMAT] CANNOT FILTER ARGS: ["my-password", "my-login"]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activejob-filtering.

License

The gem is available as open source under the terms of the MIT License.

activejob-filtering's People

Contributors

pinifloyd 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.