active_storage_silent_logs 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 772fc4a80106efe09e4a9e49ebb23d7b66c4a299
4
- data.tar.gz: 3fbc28328723a813c6c0092dde3f334b8848c6cb
2
+ SHA256:
3
+ metadata.gz: 385f684a5006952f768e6a13c4c4ae16bf5d91d7746cb314c81933c64e42c3ff
4
+ data.tar.gz: 73bf38fd7e80c3456316221496e8c0e5fa11bae9beeefdfb50865df1876d09bb
5
5
  SHA512:
6
- metadata.gz: bea68343b0e85073188138cb6d2567b7ac29c69dd82bc8c2c88bf4e936ae5665258a886470a1885b0f7440e570a4fe52ab32bc483b6490c3e297179937f13f1d
7
- data.tar.gz: 96a0c5f1332326d020c6e6bc8dc1dd0489431e3a7f5c51b5015cc332b91dd09004dafcc1579c44d5176f3e7bcc9027c234bdad6add0deae4b542570bb51b28a3
6
+ metadata.gz: cd9f975794edc04c7f3ac615e925f0ef49ac8181952bcf8c62b88e5821c58b47b7359cfd4630b64e317620613588541d952751da6ff6b3292abfdd660479c1ae
7
+ data.tar.gz: 971064ac28ed630b25bf71840538e92b41357dd98867c5a3cdf82dd8907c587c881a7d07e43353026df7ab5f8ced75b8dab2559606080bb587335b6e5ef0fad8
data/README.md CHANGED
@@ -8,12 +8,18 @@ Processing by ActiveStorage::DiskController#show as PNG
8
8
  Parameters: {"content_type"=>"image/png", "disposition"=>"inline; filename=\"image.png\"; filename*=UTF-8''image.png", "encoded_key"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaDExUkhSelFuaHpNbVJyV1dsNFVsaGpaMXBTYVV0YWNGUUdPZ1pGVkE9PSIsImV4cCI6IjIwMTgtMDgtMjlUMTQ6MzA6MjAuMjE3WiIsInB1ciI6ImJsb2Jfa2V5In19--96a1e9bc562decfc1b9c22ebde2e57029ed5ea20", "filename"=>"image"}
9
9
  ```
10
10
 
11
+ In console it looks like:
12
+
13
+ [![Sample](https://raw.githubusercontent.com/igorkasyanchuk/active_storage_silent_logs/master/docs/log.png)](https://raw.githubusercontent.com/igorkasyanchuk/active_storage_silent_logs/master/docs/log.png)
14
+
11
15
  I think no. It looks like a garbage.
12
16
 
13
17
  Imagine you have 1000 images to show! How long you need to scroll to see log of main request?
14
18
 
15
19
  So if you want this gem can hide such logs for you. Very useful for development.
16
20
 
21
+ ** Since Rails logger is not thread-safe this gem doesn't fix all messages, since one thread could impact another. If you want to hide - run puma with only one thread (open `puma.rb` and put `threads_count = ENV.fetch("RAILS_MAX_THREADS") { 1 }`).**
22
+
17
23
  ## Usage
18
24
 
19
25
  Just add gem into `Gemfile` in Rails app.
@@ -22,7 +28,7 @@ Just add gem into `Gemfile` in Rails app.
22
28
 
23
29
 
24
30
  ```ruby
25
- gem 'active_storage_silent_logs', group: [:development, :test]
31
+ gem 'active_storage_silent_logs', group: :development
26
32
  ```
27
33
 
28
34
  And then execute:
@@ -33,9 +39,13 @@ $ bundle
33
39
  ## TODO
34
40
  * verify with other storages (s3 and other cloud services)
35
41
  * can we disable puma logger?
42
+ * is it possible to fix issue with thread-safe with logger?
36
43
 
37
44
  ## Contributing
45
+
38
46
  You are welcome to contribute and help with testing.
39
47
 
48
+ To play with gem open `test/dummy` and run `rake db:migrate` + `rails s -b 0.0.0.0 puma`.
49
+
40
50
  ## License
41
51
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,40 +1,3 @@
1
- require "active_storage_silent_logs/railtie"
2
-
3
- module ActiveStorageSilentLogs
4
- class SilentLogger
5
- KEY = 'active_storage_silent_logs.old_level'.freeze
6
- FORMAT = /rails\/active_storage/.freeze
7
-
8
- def initialize(app)
9
- @app = app
10
- end
11
-
12
- def call(env)
13
- if skip?(env)
14
- tssss(env) do
15
- @app.call(env)
16
- end
17
- else
18
- @app.call(env)
19
- end
20
- end
21
-
22
- def tssss(env)
23
- env[KEY] = Rails.logger.level
24
- begin
25
- Rails.logger.level = Logger::ERROR
26
- yield
27
- ensure
28
- Rails.logger.level = env[KEY] if env[KEY]
29
- end
30
- end
31
-
32
-
33
- private
34
-
35
- def skip?(env)
36
- env['PATH_INFO'] =~ FORMAT
37
- end
38
-
39
- end
40
- end
1
+ require "active_storage_silent_logs/silent_logger"
2
+ require "active_storage_silent_logs/controller"
3
+ require "active_storage_silent_logs/railtie"
@@ -0,0 +1,20 @@
1
+ module ActiveStorageSilentLogs
2
+ module Controller
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ around_action :__with_no_logger
7
+ end
8
+
9
+ def __with_no_logger
10
+ old_level = Rails.logger.level
11
+ begin
12
+ Rails.logger.level = Logger::ERROR
13
+ yield
14
+ ensure
15
+ Rails.logger.level = old_level
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -1,9 +1,11 @@
1
1
  module ActiveStorageSilentLogs
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer "active_storage_silent_logs" do
4
- #Rails.application.middleware.use ActiveStorageSilentLogs::SilentLogger
5
-
6
4
  Rails.application.config.middleware.insert_before Rack::Sendfile, ActiveStorageSilentLogs::SilentLogger
5
+
6
+ ActiveStorage::BaseController.send :include, ActiveStorageSilentLogs::Controller
7
+
8
+ Rails.application.config.filter_parameters += [:content_type, :disposition, :encoded_key, :signed_blob_id, :variation_key]
7
9
  end
8
10
  end
9
11
  end
@@ -0,0 +1,41 @@
1
+ module ActiveStorageSilentLogs
2
+ class SilentLogger
3
+ KEY = 'active_storage_silent_logs.old_level'.freeze
4
+ FORMAT = /rails\/active_storage/.freeze
5
+
6
+ attr_reader :level
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ @level = Rails.logger.level
11
+ end
12
+
13
+ def call(env)
14
+ if skip?(env)
15
+ tssss(env) { @app.call(env) }
16
+ else
17
+ @app.call(env)
18
+ end
19
+ end
20
+
21
+ def tssss(env)
22
+ begin
23
+ Rails.logger.level = Logger::ERROR
24
+ yield
25
+ ensure
26
+ Rails.logger.level = level
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def skip?(env)
33
+ env['PATH_INFO'] =~ FORMAT
34
+ end
35
+
36
+ def whats_is_going_on
37
+ puts "===================== #{Rails.logger.level}"
38
+ end
39
+
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveStorageSilentLogs
2
- VERSION = '0.1'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage_silent_logs
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -77,7 +77,9 @@ files:
77
77
  - README.md
78
78
  - Rakefile
79
79
  - lib/active_storage_silent_logs.rb
80
+ - lib/active_storage_silent_logs/controller.rb
80
81
  - lib/active_storage_silent_logs/railtie.rb
82
+ - lib/active_storage_silent_logs/silent_logger.rb
81
83
  - lib/active_storage_silent_logs/version.rb
82
84
  - lib/tasks/active_storage_silent_logs_tasks.rake
83
85
  homepage: https://github.com/igorkasyanchuk/active_storage_silent_logs
@@ -100,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
102
  version: '0'
101
103
  requirements: []
102
104
  rubyforge_project:
103
- rubygems_version: 2.6.8
105
+ rubygems_version: 2.7.6
104
106
  signing_key:
105
107
  specification_version: 4
106
108
  summary: Silent your Active Storage logs to avoid "noise" in logs.