Skip to content

Commit

Permalink
Add Bizside::Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
m-shimojo committed Aug 14, 2024
1 parent 2ae4c0f commit 7f560f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## master
* Bizside::Logger の導入
* `ignore_paths` に正規表現あるいは文字列を指定すると、一致する `REQUEST_URI` へのアクセスログを抑制できます。

## 3.0.0
* Ruby 2.5 のサポート廃止
* CarrierWave v3 のサポート
Expand Down
28 changes: 28 additions & 0 deletions lib/bizside/logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Bizside
class Logger < ::Rails::Rack::Logger
def initialize(app, taggers = nil, config = {})
super(app, taggers)
@config = config
@config[:ignore_paths] ||= []
end

def ignore?(env)
@config[:ignore_paths].any? do |path|
case path
when Regexp
env['REQUEST_URI'] =~ path
else
env['REQUEST_URI'] == path
end
end
end

def call(env)
if ignore?(env)
::Rails.logger.silence { super }
else
super
end
end
end
end

0 comments on commit 7f560f8

Please sign in to comment.