memolog 0.3.0 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e99e3c68b6d46dff6769d0526a9b9638d6ddf479665929a8e03dddb5eeddf618
4
- data.tar.gz: f7221b929323ff44066403d01a3f02eefb6dd8302c882a2a78df43776acdc03b
3
+ metadata.gz: 4c73ff6eb1b46572a24b11def4c3b3a8a19c68562cec12d3c71331c0429f449a
4
+ data.tar.gz: 92a591f3707ad982c923c86392c9b3204ab8348a27a006320f91ea27ca9122aa
5
5
  SHA512:
6
- metadata.gz: 35f308119cb2c44d09974ce1f9fda973e648212aefb36d6256678d0b281de6784be265bc87781b55f3aa05d5a3d6ddfdd60beb86e77420f629fab02e72e87be7
7
- data.tar.gz: 3a82f19378b63f47ffcd9ad512ee44a2daa4769ffdaed6b01cd90e867e3cea31c200d264820f91af8307f0e43bb3a2c03944aa0d107bd2beeb6e6464a46cb8c7
6
+ metadata.gz: 542f4e56cd23a025151c4b4d0f5ba4c9ffb2b002fb9e87c35170bea903c4d82f722501f5b4a6954af06638ea74795609491b5709511476a49d82ad4011d3918c
7
+ data.tar.gz: 681b07990f0f8e74ebed98ea43d54bbabb228ea636c140bc56aa8f9f06c75b0340bff019a2367a44c9d971b26b01b6a9957a4dcb7d78540dd1b166d5d68bbec1
data/Gemfile CHANGED
@@ -10,6 +10,4 @@ gem "rails"
10
10
  gem "rake"
11
11
  gem "rspec"
12
12
  gem "rubocop-config-umbrellio"
13
- gem "sentry-ruby"
14
- gem "sentry-sidekiq"
15
13
  gem "sidekiq"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- memolog (0.3.0)
4
+ memolog (0.3.4)
5
5
  logger (~> 1.4.3)
6
6
  securerandom (~> 0.1.0)
7
7
 
@@ -75,25 +75,6 @@ GEM
75
75
  crass (1.0.6)
76
76
  diff-lcs (1.4.4)
77
77
  erubi (1.10.0)
78
- faraday (1.8.0)
79
- faraday-em_http (~> 1.0)
80
- faraday-em_synchrony (~> 1.0)
81
- faraday-excon (~> 1.1)
82
- faraday-httpclient (~> 1.0.1)
83
- faraday-net_http (~> 1.0)
84
- faraday-net_http_persistent (~> 1.1)
85
- faraday-patron (~> 1.0)
86
- faraday-rack (~> 1.0)
87
- multipart-post (>= 1.2, < 3)
88
- ruby2_keywords (>= 0.0.4)
89
- faraday-em_http (1.0.0)
90
- faraday-em_synchrony (1.0.0)
91
- faraday-excon (1.1.0)
92
- faraday-httpclient (1.0.1)
93
- faraday-net_http (1.0.1)
94
- faraday-net_http_persistent (1.2.0)
95
- faraday-patron (1.0.0)
96
- faraday-rack (1.0.0)
97
78
  globalid (0.5.2)
98
79
  activesupport (>= 5.0)
99
80
  i18n (1.8.10)
@@ -108,7 +89,6 @@ GEM
108
89
  method_source (1.0.0)
109
90
  mini_mime (1.1.1)
110
91
  minitest (5.14.4)
111
- multipart-post (2.1.1)
112
92
  nio4r (2.5.8)
113
93
  nokogiri (1.12.5-x86_64-darwin)
114
94
  racc (~> 1.4)
@@ -201,18 +181,7 @@ GEM
201
181
  rubocop-sequel (0.2.0)
202
182
  rubocop (~> 1.0)
203
183
  ruby-progressbar (1.11.0)
204
- ruby2_keywords (0.0.5)
205
184
  securerandom (0.1.1)
206
- sentry-ruby (4.7.3)
207
- concurrent-ruby (~> 1.0, >= 1.0.2)
208
- faraday (>= 1.0)
209
- sentry-ruby-core (= 4.7.3)
210
- sentry-ruby-core (4.7.3)
211
- concurrent-ruby
212
- faraday
213
- sentry-sidekiq (4.7.3)
214
- sentry-ruby-core (~> 4.7.0)
215
- sidekiq (>= 3.0)
216
185
  sidekiq (6.2.2)
217
186
  connection_pool (>= 2.2.2)
218
187
  rack (~> 2.0)
@@ -244,8 +213,6 @@ DEPENDENCIES
244
213
  rake
245
214
  rspec
246
215
  rubocop-config-umbrellio
247
- sentry-ruby
248
- sentry-sidekiq
249
216
  sidekiq
250
217
 
251
218
  BUNDLED WITH
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Memolog
2
2
 
3
3
  Memolog is an in-memory logger, which extend any other logger.
4
- Designed to work with [Sentry](https://github.com/getsentry/sentry-ruby).
5
- It adds `memolog` extra section to Sentry errors.
4
+ Designed to work with [Sentry](https://github.com/getsentry/sentry-ruby) but it's not necessary.
6
5
 
7
6
  ## Installation
8
7
 
@@ -28,31 +27,36 @@ Use this example during application initialization process (this example impleme
28
27
  Memolog.configure do |config|
29
28
  config.debug = false
30
29
  config.formatter = ::Memolog::Formatter.new
31
- config.initializers = %i[rails sentry sidekiq]
30
+ config.middlewares = %i[rails sidekiq]
32
31
  config.log_size_limit = 50_000
33
- config.sentry_key = :memolog
34
32
  config.uuid_callable = -> { SecureRandom.uuid }
35
33
  end
36
34
 
37
- Memolog.init!
35
+ Memolog.init_middlewares!
38
36
  ```
39
37
 
40
38
  Available options are:
41
39
  - `debug` - set it to true if you need to leave Memolog.dump result outside `Memolog.run {}` block.
42
40
  - `formatter` - setup your own formatter.
43
- - `initializers` - define here what you want to initialize in `#init!` call.
44
- - `log_size_limit` - max log length in Sentry event.
45
- - `sentry_key` - key name in Sentry extra object.
41
+ - `middlewares` - define here what you want to initialize in `#init_middlewares!` call.
42
+ - `log_size_limit` - max log length in `#dump`.
46
43
  - `uuid_callable` - Memolog add unique value to logs, here you can redefine uuid generation.
47
44
 
45
+ If you want to apply Sentry monkey patch that call `Memolog.dump` before `Sentry.capture_exception`
46
+ and `Sentry.capture_message` you can implement it via this code:
47
+
48
+ ```ruby
49
+ Sentry.prepend(Memolog::SentryExtension)
50
+ ```
51
+
48
52
  ## Usage
49
53
 
50
54
  Please call `Memolog.extend_logger(Rails.logger)` or any other logger you want to collect.
51
- After that when error occured you can check your Sentry report and see `memolog` section with all
52
- logs collected before error. Also there will be unique identifier to find logs behaviour on your
53
- server or log collection system.
55
+ After that when error occured you can call `Memolog.dump` in your code and get log from
56
+ `Rails.logger` so you can collect it to another place (Sentry or etc). Also there will be unique
57
+ identifier to find logs behaviour on your server or log collection system.
54
58
 
55
- Memolog has init code for Rails (Middleware), Sentry (Extension) and Sidekiq (Middleware).
59
+ Memolog has init code for Rails (Middleware) and Sidekiq (Middleware).
56
60
  It implement all hacks on the `Memolog.init!` call.
57
61
  Also you can add `Memolog.run {}` around logs you want to collect and release it with `Memolog.dump`
58
62
  inside this block.
@@ -3,17 +3,15 @@
3
3
  Memolog::Config = Struct.new(
4
4
  :debug,
5
5
  :formatter,
6
- :initializers,
6
+ :middlewares,
7
7
  :log_size_limit,
8
- :sentry_key,
9
8
  :uuid_callable,
10
9
  ) do
11
10
  def initialize
12
11
  self.debug = false
13
12
  self.formatter = ::Memolog::Formatter.new
14
- self.initializers = %i[rails sentry sidekiq]
13
+ self.middlewares = %i[rails sidekiq]
15
14
  self.log_size_limit = 50_000
16
- self.sentry_key = :memolog
17
15
  self.uuid_callable = -> { SecureRandom.uuid }
18
16
  end
19
17
  end
data/lib/memolog/init.rb CHANGED
@@ -1,35 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Memolog::Init
4
- def call
5
- init_rails!
6
- init_sentry!
7
- init_sidekiq!
8
- end
3
+ module Memolog::Init
4
+ extend self
9
5
 
10
- private
6
+ def init_middlewares!
7
+ init_rails_middleware!
8
+ init_sidekiq_middleware!
9
+ end
11
10
 
12
- def init_rails!
13
- return unless Memolog.config.initializers.include?(:rails)
11
+ def init_rails_middleware!
12
+ return unless Memolog.config.middlewares.include?(:rails)
14
13
  return unless Object.const_defined?("Rails")
15
14
  return if Object.const_defined?("Sidekiq") && Sidekiq.server?
16
15
 
17
- Rails.application.middleware.insert_before(0, Memolog::Middleware)
18
- end
19
-
20
- def init_sentry!
21
- return unless Memolog.config.initializers.include?(:sentry)
22
- return unless Object.const_defined?("Sentry::Scope")
23
-
24
- Sentry::Scope.prepend(Memolog::SentryScopeExtension)
16
+ Rails.application.middleware.insert_before(0, Memolog::RailsMiddleware)
25
17
  end
26
18
 
27
- def init_sidekiq!
28
- return unless Memolog.config.initializers.include?(:sidekiq)
29
- return unless Object.const_defined?("Sentry::Sidekiq::SentryContextServerMiddleware")
19
+ def init_sidekiq_middleware!
20
+ return unless Memolog.config.middlewares.include?(:sidekiq)
21
+ return unless Object.const_defined?("Sidekiq")
30
22
 
31
- Sentry::Sidekiq::SentryContextServerMiddleware.prepend(
32
- Memolog::SentrySidekiqMiddlewareExtension,
33
- )
23
+ Sidekiq.configure_server do |config|
24
+ config.server_middleware do |chain|
25
+ chain.prepend(Memolog::SidekiqMiddleware)
26
+ end
27
+ end
34
28
  end
35
29
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Memolog::Extension
3
+ module Memolog::LoggerExtension
4
4
  def add(*args, &block)
5
5
  Memolog.logger.log(*args, &block)
6
6
  super
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Memolog::Middleware
3
+ class Memolog::RailsMiddleware
4
4
  def initialize(app)
5
5
  @app = app
6
6
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memolog::SentryExtension
4
+ def self.prepended(base)
5
+ base.singleton_class.send(:prepend, ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def capture_exception(exception, **options, &block)
10
+ set_extras_memolog!
11
+ super
12
+ end
13
+
14
+ def capture_message(message, **options, &block)
15
+ set_extras_memolog!
16
+ super
17
+ end
18
+
19
+ def set_extras_memolog!
20
+ return unless get_current_scope
21
+ set_extras(memolog: Memolog.dump)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Memolog::SidekiqMiddleware
4
+ def call(*)
5
+ Memolog.run { yield } # rubocop:disable Style/ExplicitBlockArgument
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Memolog
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.4"
5
5
  end
data/lib/memolog.rb CHANGED
@@ -6,31 +6,30 @@ require "stringio"
6
6
 
7
7
  require "memolog/version"
8
8
  require "memolog/config"
9
- require "memolog/extension"
10
9
  require "memolog/formatter"
11
10
  require "memolog/init"
12
- require "memolog/middleware"
13
- require "memolog/sentry_scope_extension"
14
- require "memolog/sentry_sidekiq_middleware_extension"
11
+ require "memolog/logger_extension"
12
+ require "memolog/rails_middleware"
13
+ require "memolog/sentry_extension"
14
+ require "memolog/sidekiq_middleware"
15
15
 
16
16
  module Memolog
17
17
  extend self
18
18
 
19
- attr_accessor :config, :logdevs
19
+ attr_accessor :config
20
20
 
21
21
  @config = Memolog::Config.new
22
- @logdevs = []
23
22
 
24
23
  def configure
25
24
  yield(config) if block_given?
26
25
  end
27
26
 
28
- def init!
29
- Memolog::Init.new.call
27
+ def init_middlewares!
28
+ Memolog::Init.init_middlewares!
30
29
  end
31
30
 
32
31
  def extend_logger(other_logger)
33
- other_logger.extend(Memolog::Extension)
32
+ other_logger.extend(Memolog::LoggerExtension)
34
33
  other_logger.formatter = config.formatter
35
34
  end
36
35
 
@@ -42,6 +41,10 @@ module Memolog
42
41
  Thread.current[:memolog_logger] ||= Logger.new(nil, formatter: config.formatter)
43
42
  end
44
43
 
44
+ def logdevs
45
+ Thread.current[:memolog_logdevs] ||= []
46
+ end
47
+
45
48
  def run
46
49
  Thread.current[:memolog_uuid] = config.uuid_callable.call
47
50
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memolog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stepan Kirushkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-21 00:00:00.000000000 Z
11
+ date: 2021-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger
@@ -61,12 +61,12 @@ files:
61
61
  - bin/setup
62
62
  - lib/memolog.rb
63
63
  - lib/memolog/config.rb
64
- - lib/memolog/extension.rb
65
64
  - lib/memolog/formatter.rb
66
65
  - lib/memolog/init.rb
67
- - lib/memolog/middleware.rb
68
- - lib/memolog/sentry_scope_extension.rb
69
- - lib/memolog/sentry_sidekiq_middleware_extension.rb
66
+ - lib/memolog/logger_extension.rb
67
+ - lib/memolog/rails_middleware.rb
68
+ - lib/memolog/sentry_extension.rb
69
+ - lib/memolog/sidekiq_middleware.rb
70
70
  - lib/memolog/version.rb
71
71
  homepage: https://github.com/skirushkin/memolog
72
72
  licenses:
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Memolog::SentryScopeExtension
4
- def apply_to_event(scope, hint = nil)
5
- memolog_dump = Memolog.dump
6
- set_extras(Memolog.config.sentry_key => memolog_dump) if memolog_dump
7
-
8
- super
9
- end
10
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Memolog::SentrySidekiqMiddlewareExtension
4
- def call(worker, job, queue)
5
- Memolog.run { super }
6
- end
7
- end