lograge 0.3.1 → 0.3.2

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: 7e83952d334c15f42c841f0ed45c8e1538e795ab
4
- data.tar.gz: 581be0bc6a70dfa1abaad4bbefef0a80115f837c
3
+ metadata.gz: a85786ea77c363233831965c6e03f24bca37cd24
4
+ data.tar.gz: 9d1c277d2df5eda46969e444aa356ba99ea40e89
5
5
  SHA512:
6
- metadata.gz: f21494756b287b5d0c95594f9a285b70e2af281f9b25a19f4e2c90a4656058cadc869337f9671002af5403ffc2331b8a3e1230ba3363e0c7b861e7569f8fb30c
7
- data.tar.gz: 09f4b1e38c61db6caff08c51019ffdb982f2b7ca536ea5be7edbbd9a113fb48ca3dbb041603737cedaf810cbcb85c48b9d9a166fd330de7ca0639523d53ccb3d
6
+ metadata.gz: c008c958f766ae2a01360c5873320f13cb22065a3fe5b61ec873ef078d85bbcfba2f5d2a5f6e164ab996f565be1f73a7e48efe0c6fe4b210f94180b3904446cb
7
+ data.tar.gz: eb3f7560580199ecde41d01740dc4a95b8b6a4d3e31c82035e0c8bc899009d29553fb649b46c8913981730bc1a7f33046080e423cd10655c1b0ccf1dcf7b4ca9
data/lib/lograge.rb CHANGED
@@ -12,6 +12,7 @@ require 'active_support/core_ext/module/attribute_accessors'
12
12
  require 'active_support/core_ext/string/inflections'
13
13
  require 'active_support/ordered_options'
14
14
 
15
+ # rubocop:disable ModuleLength
15
16
  module Lograge
16
17
  module_function
17
18
 
@@ -26,7 +27,7 @@ module Lograge
26
27
  mattr_writer :custom_options
27
28
  self.custom_options = nil
28
29
 
29
- def self.custom_options(event)
30
+ def custom_options(event)
30
31
  if @@custom_options.respond_to?(:call)
31
32
  @@custom_options.call(event)
32
33
  else
@@ -40,7 +41,7 @@ module Lograge
40
41
  mattr_writer :before_format
41
42
  self.before_format = nil
42
43
 
43
- def self.before_format(data, payload)
44
+ def before_format(data, payload)
44
45
  result = nil
45
46
  result = @@before_format.call(data, payload) if @@before_format
46
47
  result || data
@@ -58,7 +59,7 @@ module Lograge
58
59
  # are given to 'ignore'. Both methods can be called multiple times, which
59
60
  # just adds more ignore conditions to a list that is checked before logging.
60
61
 
61
- def self.ignore_actions(actions)
62
+ def ignore_actions(actions)
62
63
  ignore(lambda do |event|
63
64
  params = event.payload[:params]
64
65
  Array(actions).include?("#{params['controller']}##{params['action']}")
@@ -69,7 +70,7 @@ module Lograge
69
70
  @ignore_tests ||= []
70
71
  end
71
72
 
72
- def self.ignore(test)
73
+ def ignore(test)
73
74
  ignore_tests.push(test) if test
74
75
  end
75
76
 
@@ -77,7 +78,7 @@ module Lograge
77
78
  @ignore_tests = []
78
79
  end
79
80
 
80
- def self.ignore?(event)
81
+ def ignore?(event)
81
82
  ignore_tests.any? { |ignore_test| ignore_test.call(event) }
82
83
  end
83
84
 
@@ -92,7 +93,7 @@ module Lograge
92
93
  # - :logstash - JSON formatted as a Logstash Event.
93
94
  mattr_accessor :formatter
94
95
 
95
- def self.remove_existing_log_subscriptions
96
+ def remove_existing_log_subscriptions
96
97
  ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
97
98
  case subscriber
98
99
  when ActionView::LogSubscriber
@@ -103,7 +104,7 @@ module Lograge
103
104
  end
104
105
  end
105
106
 
106
- def self.unsubscribe(component, subscriber)
107
+ def unsubscribe(component, subscriber)
107
108
  events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
108
109
  events.each do |event|
109
110
  ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
@@ -114,27 +115,54 @@ module Lograge
114
115
  end
115
116
  end
116
117
 
117
- def self.setup(app)
118
+ def setup(app)
118
119
  self.application = app
119
- app.config.action_dispatch.rack_cache[:verbose] = false if app.config.action_dispatch.rack_cache
120
+ disable_rack_cache_verbose_output
121
+ keep_original_rails_log
120
122
 
121
- unless app.config.lograge.keep_original_rails_log
122
- require 'lograge/rails_ext/rack/logger'
123
- Lograge.remove_existing_log_subscriptions
124
- end
123
+ attach_to_action_controller
124
+ set_lograge_log_options
125
+ support_deprecated_config # TODO: Remove with version 1.0
126
+ set_formatter
127
+ set_ignores
128
+ end
125
129
 
126
- Lograge.logger = app.config.lograge.logger
130
+ def set_ignores
131
+ Lograge.ignore_actions(lograge_config.ignore_actions)
132
+ Lograge.ignore(lograge_config.ignore_custom)
133
+ end
127
134
 
135
+ def set_formatter
136
+ Lograge.formatter = lograge_config.formatter || Lograge::Formatters::KeyValue.new
137
+ end
138
+
139
+ def attach_to_action_controller
128
140
  Lograge::RequestLogSubscriber.attach_to :action_controller
141
+ end
142
+
143
+ def set_lograge_log_options
144
+ Lograge.logger = lograge_config.logger
129
145
  Lograge.custom_options = lograge_config.custom_options
130
146
  Lograge.before_format = lograge_config.before_format
131
147
  Lograge.log_level = lograge_config.log_level || :info
132
- support_deprecated_config # TODO: Remove with version 1.0
133
- Lograge.formatter = lograge_config.formatter || Lograge::Formatters::KeyValue.new
134
- Lograge.ignore_actions(lograge_config.ignore_actions)
135
- Lograge.ignore(lograge_config.ignore_custom)
136
148
  end
137
149
 
150
+ def disable_rack_cache_verbose_output
151
+ application.config.action_dispatch.rack_cache[:verbose] = false if rack_cache_hashlike?(application)
152
+ end
153
+
154
+ def keep_original_rails_log
155
+ return if lograge_config.keep_original_rails_log
156
+
157
+ require 'lograge/rails_ext/rack/logger'
158
+ Lograge.remove_existing_log_subscriptions
159
+ end
160
+
161
+ def rack_cache_hashlike?(app)
162
+ app.config.action_dispatch.rack_cache && app.config.action_dispatch.rack_cache.respond_to?(:[]=)
163
+ end
164
+ private_class_method :rack_cache_hashlike?
165
+
138
166
  # TODO: Remove with version 1.0
139
167
 
140
168
  def support_deprecated_config
@@ -5,7 +5,7 @@ module Lograge
5
5
  load_dependencies
6
6
  event = LogStash::Event.new(data)
7
7
 
8
- event.message = "[#{data[:status]}] #{data[:method]} #{data[:path]} (#{data[:controller]}##{data[:action]})"
8
+ event['message'] = "[#{data[:status]}] #{data[:method]} #{data[:path]} (#{data[:controller]}##{data[:action]})"
9
9
  event.to_json
10
10
  end
11
11
 
@@ -1,5 +1,4 @@
1
1
  require 'json'
2
-
3
2
  require 'active_support/core_ext/class/attribute'
4
3
  require 'active_support/log_subscriber'
5
4
 
@@ -10,7 +9,7 @@ module Lograge
10
9
 
11
10
  payload = event.payload
12
11
 
13
- data = extract_request(payload)
12
+ data = extract_request(payload)
14
13
  extract_status(data, payload)
15
14
  runtimes(data, event)
16
15
  location(data)
@@ -62,13 +61,19 @@ module Lograge
62
61
  data[:status] = status.to_i
63
62
  elsif (error = payload[:exception])
64
63
  exception, message = error
65
- data[:status] = 500
66
- data[:error] = "#{exception}:#{message}"
64
+ data[:status] = get_error_status_code(exception)
65
+ data[:error] = "#{exception}: #{message}"
67
66
  else
68
67
  data[:status] = 0
69
68
  end
70
69
  end
71
70
 
71
+ def get_error_status_code(exception)
72
+ exception_object = exception.constantize.new
73
+ exception_wrapper = ::ActionDispatch::ExceptionWrapper.new({}, exception_object)
74
+ exception_wrapper.status_code
75
+ end
76
+
72
77
  def custom_options(data, event)
73
78
  options = Lograge.custom_options(event)
74
79
  data.merge! options if options
@@ -1,3 +1,3 @@
1
1
  module Lograge
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lograge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-17 00:00:00.000000000 Z
12
+ date: 2015-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -127,3 +127,4 @@ signing_key:
127
127
  specification_version: 4
128
128
  summary: Tame Rails' multi-line logging into a single line per request
129
129
  test_files: []
130
+ has_rdoc: