ezlog 0.3.5 → 0.4.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
  SHA256:
3
- metadata.gz: e73705d16d2f3167345f05a0850bcd9b249609d38717d132bad505c52ffa029f
4
- data.tar.gz: 565ad4f1d10bfd60cfec96c06f86ee8295974d19fcd4493fba12bdb4a94098d1
3
+ metadata.gz: a13352755faf442588dbe56813e8cc770f94c088455497f98b7d826ced91ff10
4
+ data.tar.gz: ea44535055ff6b6d33809e826113a4121277dc9c7e74faaf82f7516e40301daa
5
5
  SHA512:
6
- metadata.gz: fedd5799e21e4f258bd90c20467026369dc96e51aebfb9a62703c82d3f4381680fd22a0546711610de429ddfefe741f07e60960f6c8cd60ce9bd22541faece3c
7
- data.tar.gz: 223cc4fb2d1aee674ed7281d369154b857cc4ed5a4ea5a47c64b58ca5f8d7cd1c9194ae8f2fc053cd8f792ef9d295b3dd72996aba97d82d7bcbd45a52136e132
6
+ metadata.gz: 02e113881e70f1b46123156b2cad9682100a7006b822f5c93a18200be3aba8de8cc852b904591f505236ca1d867f3eb725fd9a310fdef7e395ccf7fe85c8ee2c
7
+ data.tar.gz: 98ef1ef8fc146fd662354db14ae07febbfde6296b4545bc5aace9776164648052fd497953f68b5e7ddca3e26d99e30466bd4f10a24d0632e26f60cbbb97915ee
@@ -1,3 +1,16 @@
1
+ ### 0.4.0 (2019-09-06)
2
+
3
+ [Full Changelog](https://github.com/emartech/ezlog/compare/v0.3.5...v0.4.0)
4
+
5
+ * Features & enhancements
6
+ * Added log context management methods `within_log_context` and `add_to_log_context` to Ezlog module.
7
+ * Replaced ActiveRecord query logging with a log subscriber that logs queries via Ezlog.
8
+ * Added automatic query logging (at DEBUG level) to Sequel connections.
9
+
10
+ * Bug fixes
11
+ * ActionDispatch::DebugExceptions is no longer replaced because other gems
12
+ (like [web-console](https://github.com/rails/web-console)) are depending on it.
13
+
1
14
  ### 0.3.5 (2019-08-14)
2
15
 
3
16
  [Full Changelog](https://github.com/emartech/ezlog/compare/v0.3.4...v0.3.5)
@@ -28,5 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency "sidekiq", "~> 5.0"
31
+ spec.add_development_dependency "sequel", "~> 5.0"
31
32
  spec.add_development_dependency "actionpack", "~> 5.0"
33
+ spec.add_development_dependency "activerecord", "~> 5.0"
32
34
  end
@@ -12,4 +12,6 @@ module Ezlog
12
12
  def self.logger(name)
13
13
  ::Logging::Logger[name]
14
14
  end
15
+
16
+ extend LogContextHelper
15
17
  end
@@ -4,6 +4,7 @@ require "action_controller/log_subscriber"
4
4
  module Ezlog
5
5
  module Rails
6
6
  autoload :AccessLog, 'ezlog/rails/access_log'
7
+ autoload :ActiveRecord, 'ezlog/rails/active_record'
7
8
  autoload :DebugExceptions, 'ezlog/rails/debug_exceptions'
8
9
  autoload :LogExceptions, 'ezlog/rails/log_exceptions'
9
10
  autoload :RequestLogContext, 'ezlog/rails/request_log_context'
@@ -0,0 +1,7 @@
1
+ module Ezlog
2
+ module Rails
3
+ module ActiveRecord
4
+ autoload :LogSubscriber, 'ezlog/rails/active_record/log_subscriber'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ module Ezlog
2
+ module Rails
3
+ module ActiveRecord
4
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
5
+ def sql(event)
6
+ ::ActiveRecord::Base.logger.debug log_message_from(event)
7
+ end
8
+
9
+ private
10
+
11
+ def log_message_from(event)
12
+ basic_message_from(event).tap do |message|
13
+ params = params_from event
14
+ message[:params] = params if params.any?
15
+ end
16
+ end
17
+
18
+ def basic_message_from(event)
19
+ {
20
+ message: "SQL - #{event.payload[:name]} (#{event.duration.round(3)}ms)",
21
+ sql: event.payload[:sql],
22
+ duration_sec: (event.duration / 1000.0).round(5)
23
+ }
24
+ end
25
+
26
+ def params_from(event)
27
+ return {} if event.payload.fetch(:binds, []).empty?
28
+
29
+ params = event.payload[:binds]
30
+ values = type_casted_values_from event
31
+ param_value_pairs = params.zip(values).map do |param, value|
32
+ [param.name, value_of(param, value)]
33
+ end
34
+
35
+ Hash[param_value_pairs]
36
+ end
37
+
38
+ def type_casted_values_from(event)
39
+ binds = event.payload[:type_casted_binds]
40
+ binds.respond_to?(:call) ? binds.call : binds
41
+ end
42
+
43
+ def value_of(param, value)
44
+ param.type.binary? ? '-binary data-' : value
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ module ActionDispatch
2
+ class DebugExceptions
3
+ def skip_logging_error(_request, _wrapper)
4
+ end
5
+
6
+ alias_method :original_log_error, :log_error
7
+ alias_method :log_error, :skip_logging_error
8
+ end
9
+ end
@@ -1,15 +1,21 @@
1
1
  module Ezlog
2
2
  module Rails
3
3
  class LogSubscriber
4
- def self.detach(subscriber_class)
5
- subscriber = ::ActiveSupport::LogSubscriber.log_subscribers.find { |subscriber| subscriber.is_a? subscriber_class }
6
- return unless subscriber
4
+ class << self
5
+ def detach(subscriber_class)
6
+ subscriber = ::ActiveSupport::LogSubscriber.log_subscribers.find { |subscriber| subscriber.is_a? subscriber_class }
7
+ return unless subscriber
7
8
 
8
- subscriber.patterns.each do |pattern|
9
- ::ActiveSupport::Notifications.notifier.listeners_for(pattern).each do |listener|
10
- ::ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate').is_a? subscriber_class
9
+ subscriber.patterns.each do |pattern|
10
+ ::ActiveSupport::Notifications.notifier.listeners_for(pattern).each do |listener|
11
+ ::ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate').is_a? subscriber_class
12
+ end
11
13
  end
12
14
  end
15
+
16
+ def attach(subscriber_class, namespace)
17
+ subscriber_class.attach_to namespace
18
+ end
13
19
  end
14
20
  end
15
21
  end
@@ -1,29 +1,38 @@
1
1
  module Ezlog
2
2
  class Railtie < Rails::Railtie
3
+ initializer "ezlog.initialize" do
4
+ require "ezlog/rails/extensions"
5
+ end
6
+
3
7
  initializer 'ezlog.configure_logging' do |app|
4
8
  ::Logging.logger.root.appenders = ::Logging.appenders.stdout 'stdout', layout: Ezlog::LoggingLayout.new(environment: ::Rails.env)
5
9
  ::Logging.logger.root.level = app.config.log_level
6
10
  end
7
11
 
8
- initializer 'ezlog.configure_sidekiq_logging' do |app|
12
+ initializer 'ezlog.configure_sidekiq' do |app|
9
13
  initialize_sidekiq_logging(app) if defined? ::Sidekiq
10
14
  end
11
15
 
12
- initializer 'ezlog.configure_rack_timeout_logging' do
16
+ initializer 'ezlog.configure_sequel' do
17
+ ::Sequel::Database.extension :ezlog_logging if defined? ::Sequel
18
+ end
19
+
20
+ initializer 'ezlog.configure_rack_timeout' do
13
21
  disable_rack_timeout_logging if defined? ::Rack::Timeout
14
22
  end
15
23
 
16
- initializer 'ezlog.configure_middlewares' do |app|
24
+ initializer 'ezlog.configure_rails_middlewares' do |app|
17
25
  app.config.middleware.insert_after ::ActionDispatch::RequestId, Ezlog::Rails::RequestLogContext
18
26
  app.config.middleware.delete ::Rails::Rack::Logger
19
- app.config.middleware.swap ::ActionDispatch::DebugExceptions, Ezlog::Rails::DebugExceptions
20
- app.config.middleware.insert_before Ezlog::Rails::DebugExceptions, Ezlog::Rails::AccessLog, Ezlog.logger('AccessLog')
21
- app.config.middleware.insert_after Ezlog::Rails::DebugExceptions, Ezlog::Rails::LogExceptions, Ezlog.logger('Application')
27
+ app.config.middleware.insert_before ::ActionDispatch::DebugExceptions, Ezlog::Rails::AccessLog, Ezlog.logger('AccessLog')
28
+ app.config.middleware.insert_after ::ActionDispatch::DebugExceptions, Ezlog::Rails::LogExceptions, Ezlog.logger('Application')
22
29
  end
23
30
 
24
31
  config.after_initialize do
25
32
  Ezlog::Rails::LogSubscriber.detach ::ActionController::LogSubscriber
26
33
  Ezlog::Rails::LogSubscriber.detach ::ActionView::LogSubscriber
34
+ Ezlog::Rails::LogSubscriber.detach ::ActiveRecord::LogSubscriber
35
+ Ezlog::Rails::LogSubscriber.attach Ezlog::Rails::ActiveRecord::LogSubscriber, :active_record
27
36
  end
28
37
 
29
38
  config.before_configuration do |app|
@@ -1,3 +1,3 @@
1
1
  module Ezlog
2
- VERSION = '0.3.5'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -0,0 +1,15 @@
1
+ module Ezlog
2
+ module Sequel
3
+ module LoggingExtension
4
+ def self.extended(db)
5
+ db.instance_exec do
6
+ self.sql_log_level = :debug
7
+ self.log_connection_info = false
8
+ @loggers << Ezlog.logger('Sequel')
9
+ end
10
+ end
11
+ end
12
+
13
+ ::Sequel::Database.register_extension :ezlog_logging, LoggingExtension
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zoltan Ormandi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-14 00:00:00.000000000 Z
11
+ date: 2019-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sequel
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: actionpack
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '5.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activerecord
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '5.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '5.0'
97
125
  description:
98
126
  email:
99
127
  - zoltan.ormandi@emarsys.com
@@ -117,7 +145,9 @@ files:
117
145
  - lib/ezlog/logging_layout.rb
118
146
  - lib/ezlog/rails.rb
119
147
  - lib/ezlog/rails/access_log.rb
120
- - lib/ezlog/rails/debug_exceptions.rb
148
+ - lib/ezlog/rails/active_record.rb
149
+ - lib/ezlog/rails/active_record/log_subscriber.rb
150
+ - lib/ezlog/rails/extensions.rb
121
151
  - lib/ezlog/rails/log_exceptions.rb
122
152
  - lib/ezlog/rails/log_subscriber.rb
123
153
  - lib/ezlog/rails/request_log_context.rb
@@ -130,6 +160,7 @@ files:
130
160
  - lib/ezlog/sidekiq/job_context.rb
131
161
  - lib/ezlog/sidekiq/job_logger.rb
132
162
  - lib/ezlog/version.rb
163
+ - lib/sequel/extensions/ezlog_logging.rb
133
164
  homepage: https://github.com/emartech/ezlog
134
165
  licenses:
135
166
  - MIT
@@ -150,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
181
  - !ruby/object:Gem::Version
151
182
  version: '0'
152
183
  requirements: []
153
- rubygems_version: 3.0.1
184
+ rubygems_version: 3.0.3
154
185
  signing_key:
155
186
  specification_version: 4
156
187
  summary: A zero-configuration logging solution for projects using Sidekiq, Rails,
@@ -1,8 +0,0 @@
1
- module Ezlog
2
- module Rails
3
- class DebugExceptions < ::ActionDispatch::DebugExceptions
4
- def log_error(_request, _wrapper)
5
- end
6
- end
7
- end
8
- end