lamian 1.0.1 → 1.1.0

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
2
  SHA1:
3
- metadata.gz: c6851ffad052c2a8937a913f880a1b6a5424c218
4
- data.tar.gz: 2f3d5a8e3c67f2583d6778394f077cdfece11378
3
+ metadata.gz: 5fed5c60bd57fa0cd1e33f57ee3ffebd8009ee7c
4
+ data.tar.gz: 6c6324fa43333c990e1562e0a8cb2e63f7871496
5
5
  SHA512:
6
- metadata.gz: 2310ee71cae10bdca125a2832002bf62ad4cd98f154525afe2b3f2eba43526eb0c4ac9d09df484b23ae5d89d6e1dfdd8d40d77a8cc216fcd196b0e03a5c7aa3f
7
- data.tar.gz: '08b05982d5c0d01fd1491de1255111defa75b9cd7c188c288e8472d7123d9ed4ad8e714f34e01f47329ede890050f5ddb8369f8f7e36364cb150e4446c163aa8'
6
+ metadata.gz: e3b733bccc6a50fadefe5eac089eead5fa764a3dff4b3363049f5ad773d9f970a19b5e5e0395741ad3cd5bf8c6a7f6b01d583c9fa6d987fb4dce68c019c0034e
7
+ data.tar.gz: 6e966db934eee4fafe40ffb69c155dafb8b9f3d6ad15d53346b12b4c26a149ab1751d6bb23cfd2fd6317d05f81e3d787f965209f18bd0388771965307e8305f4
@@ -10,6 +10,8 @@ module Lamian
10
10
  autoload :Logger, "lamian/logger"
11
11
  autoload :LoggerExtension, "lamian/logger_extension"
12
12
  autoload :Middleware, "lamian/middleware"
13
+ autoload :RavenContextExtension, "lamian/raven_context_extension"
14
+ autoload :SidekiqRavenMiddleware, "lamian/sidekiq_raven_middleware"
13
15
 
14
16
  require "lamian/engine"
15
17
 
@@ -1,20 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails"
4
- require "exception_notification"
5
- require "exception_notification/rails"
6
4
 
7
5
  module Lamian
8
- # Rails engine, which injects middleware and appends
9
- # lamian views to rails library.
10
- # Lamian views are used in exception_notifier to provide
11
- # request_log section
6
+ # This engine is automatically loaded by Rails
7
+ # @see https://edgeguides.rubyonrails.org/engines.html Rails::Engine docs
12
8
  class Engine < ::Rails::Engine
13
- config.app_middleware.insert_before(
14
- ExceptionNotification::Rack,
15
- ::Lamian::Middleware,
16
- )
17
-
9
+ # Lamian views are used in exception_notifier to provide request_log section
18
10
  paths["app/views"] << "lib/lamian/rails_views"
11
+
12
+ initializer "lamian.use_rack_middleware" do |app|
13
+ # :nocov:
14
+ app.config.middleware.unshift(Lamian::Middleware)
15
+ # :nocov:
16
+ end
19
17
  end
20
18
  end
@@ -7,12 +7,6 @@ module Lamian
7
7
  # Provides thread-local loggers to catch teed messages from
8
8
  # regular loggers.
9
9
  # Uses :__lamian_logger thread variable
10
- # @attr level [Int]
11
- # current log level, implicitly set to zero
12
- # @attr logdevs [Array(StringIO)]
13
- # stack of log devices used to store logs
14
- # @attr formatter [Logger::Formatter]
15
- # formatter, inherited from Lamian.config
16
10
  class Logger < ::Logger
17
11
  # Provides access to logger bound to curent thread
18
12
  # @return [Lamian::Logger] current logger
@@ -23,22 +17,27 @@ module Lamian
23
17
  def initialize
24
18
  self.level = 0
25
19
  self.logdevs = []
26
- self.formatter = Lamian.config.formatter
27
20
  end
28
21
 
29
22
  # @see Lamian.run
30
23
  # Collects logs sent inside block
31
24
  def run
32
- push_logdev(StringIO.new)
25
+ logdevs.push(StringIO.new)
26
+
33
27
  yield
34
28
  ensure
35
- pop_logdev
29
+ logdevs.pop
36
30
  end
37
31
 
38
32
  # Part of Logger api, entry point for all logs
39
33
  # extened to run on each log device in stack
40
34
  def add(*args, &block)
41
- each_logdev { super(*args, &block) }
35
+ @formatter = Lamian.config.formatter
36
+
37
+ logdevs.each do |logdev|
38
+ @logdev = logdev
39
+ super
40
+ end
42
41
  end
43
42
 
44
43
  # @see Lamian.dump
@@ -56,7 +55,13 @@ module Lamian
56
55
 
57
56
  private
58
57
 
59
- attr_accessor :level, :logdevs, :formatter
58
+ # @return [Int]
59
+ # current log level, implicitly set to zero
60
+ attr_accessor :level
61
+
62
+ # @return [Array(StringIO)]
63
+ # stack of log devices used to store logs
64
+ attr_accessor :logdevs
60
65
 
61
66
  # Formats string using given format
62
67
  # @todo create `formatters` interface to allow real format selection
@@ -71,26 +76,5 @@ module Lamian
71
76
  return unless string
72
77
  string.gsub!(/\[\d{1,2}m/, "")
73
78
  end
74
-
75
- # Pushes new logdev in the start of #run call
76
- # @param logdev [StringIO] new StringIO
77
- def push_logdev(logdev)
78
- logdevs << logdev
79
- end
80
-
81
- # Pops logdev in the end of #run call
82
- # @return [StringIO] logdev
83
- def pop_logdev
84
- logdevs.pop
85
- end
86
-
87
- # Runs specific block with all logdevs in stack to
88
- # populate them all
89
- def each_logdev
90
- logdevs.each do |logdev|
91
- @logdev = logdev
92
- yield
93
- end
94
- end
95
79
  end
96
80
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lamian
4
- # Provides rack middleware, which allows to colelct request logs
4
+ # Provides rack middleware, which allows to collect request logs
5
5
  # @attr app [Proc] stored application
6
6
  class Middleware
7
7
  # @param app [Proc] stored application
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A patch for Raven::Context class
4
+ module Lamian::RavenContextExtension
5
+ # Adds current lamian log to the extra part of all raven events generated inside Lamian.run block
6
+ # @see https://www.rubydoc.info/gems/sentry-raven/0.9.2/Raven/Context#extra-instance_method
7
+ def extra
8
+ log = Lamian.dump(format: :txt)
9
+ return super unless log
10
+ extra = super || {}
11
+ extra.merge(lamian_log: log)
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sidekiq middleware
4
+ class Lamian::SidekiqRavenMiddleware
5
+ # Adds current lamian log to the extra part of raven events generated inside sidekiq jobs
6
+ def call(*)
7
+ Lamian.run do
8
+ begin
9
+ yield
10
+ rescue Exception # rubocop:disable Lint/RescueException
11
+ Raven.extra_context(lamian_log: Lamian.dump(format: :txt))
12
+ raise
13
+ end
14
+ end
15
+ end
16
+ end
@@ -13,5 +13,5 @@ module Lamian
13
13
  # According to this, it is enought to specify '~> a.b'
14
14
  # if private API was not used and to specify '~> a.b.c' if it was
15
15
 
16
- VERSION = "1.0.1"
16
+ VERSION = "1.1.0"
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lamian
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JelF
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-02 00:00:00.000000000 Z
11
+ date: 2018-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
- - !ruby/object:Gem::Dependency
28
- name: exception_notification
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +150,20 @@ dependencies:
164
150
  - - ">="
165
151
  - !ruby/object:Gem::Version
166
152
  version: 2.1.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: sentry-raven
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 2.7.4
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 2.7.4
167
167
  description: Add logs to your error messages, using exception_notifier or smth like
168
168
  it
169
169
  email:
@@ -180,8 +180,10 @@ files:
180
180
  - lib/lamian/middleware.rb
181
181
  - lib/lamian/rails_views/exception_notifier/_request_log.html.erb
182
182
  - lib/lamian/rails_views/exception_notifier/_request_log.text.erb
183
+ - lib/lamian/raven_context_extension.rb
184
+ - lib/lamian/sidekiq_raven_middleware.rb
183
185
  - lib/lamian/version.rb
184
- homepage: https://github.com/JelF/lamian
186
+ homepage: https://github.com/umbrellio/lamian
185
187
  licenses: []
186
188
  metadata: {}
187
189
  post_install_message:
@@ -200,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
202
  version: '0'
201
203
  requirements: []
202
204
  rubyforge_project:
203
- rubygems_version: 2.5.2
205
+ rubygems_version: 2.5.2.3
204
206
  signing_key:
205
207
  specification_version: 4
206
208
  summary: Add logs to your error messages