ocean-rails 1.29.4 → 1.29.5

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
  SHA1:
3
- metadata.gz: f62098771fbece3d538d3fc124ab745e3b345400
4
- data.tar.gz: ec0ec9a930e28e7f088098a078a1e25d3f99c129
3
+ metadata.gz: d3158e42571cf6f00d22e0673c30d2d60b40612d
4
+ data.tar.gz: 1e0c86ded7990b0957cd3b1f2c30e7d9bd43c03d
5
5
  SHA512:
6
- metadata.gz: 788db4f9e35dc3d4172e4f82b16e6124e87238d605c66df55b1e5f879d0ac883218a488b6ad1bf5c7b3fb42dbae045fbfa949b10eeea66cf243d63d75f7ee90f
7
- data.tar.gz: cd36f14e52ad7095afb4efa3a2206865817012af080cea1ab0b62721ead56c0d8cc88787c535576f71a9daa3b369eb580bd3ffd436de5db2f92eb76618650ef5
6
+ metadata.gz: d2b4c2823bf36030c272d0e8650ab15620248d34348336470cff7fa5055c5c720b043df74c71ab4c836bd38f07e43c686334e9480e91a852770345834296f65c
7
+ data.tar.gz: e8830b8a60562633db5a8604c2570eab91a4314db2ab5e4a54403b9325894549b12188e6138ddcd874d4c2f2cdc4b3f2dfef9c7bb4732abb9d3d05b017b0fb9b
@@ -0,0 +1,107 @@
1
+ exit unless Rails.env == 'production'
2
+
3
+ def remove_existing_log_subscriptions
4
+ ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
5
+ case subscriber
6
+ when ActionView::LogSubscriber
7
+ unsubscribe(:action_view, subscriber)
8
+ when ActionController::LogSubscriber
9
+ unsubscribe(:action_controller, subscriber)
10
+ end
11
+ end
12
+ end
13
+
14
+ def unsubscribe(component, subscriber)
15
+ events = subscriber.public_methods(false).reject{ |method| method.to_s == 'call' }
16
+ events.each do |event|
17
+ ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
18
+ if listener.instance_variable_get('@delegate') == subscriber
19
+ ActiveSupport::Notifications.unsubscribe listener
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ remove_existing_log_subscriptions
26
+
27
+
28
+ ActiveSupport::Notifications.subscribe "halted_callback.action_controller" do |*args|
29
+ data = args.extract_options!
30
+ Thread.current[:filter] = data[:filter]
31
+ end
32
+
33
+
34
+ INTERNAL_PARAMS = %w(controller action format _method only_path)
35
+
36
+ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, started, finished, unique_id, payload|
37
+ path = payload[:path]
38
+ if path != '/alive'
39
+
40
+ runtime = finished - started
41
+ param_method = payload[:params]['_method']
42
+ method = param_method ? param_method.upcase : payload[:method]
43
+ status = compute_status(payload)
44
+ params = payload[:params].except(*INTERNAL_PARAMS)
45
+
46
+ data = {
47
+ timestamp: (started.utc.to_f * 1000).to_i,
48
+ method: method,
49
+ status: status,
50
+ runtime: (runtime * 1000).round(0),
51
+ view_runtime: payload[:view_runtime].round(0),
52
+ db_runtime: payload[:db_runtime].round(0)
53
+ }
54
+ data[:params] = params if params.present?
55
+ data[:filter] = Thread.current[:filter] if Thread.current[:filter]
56
+
57
+ Thread.current[:logdata] = data
58
+ end
59
+ end
60
+
61
+ def compute_status payload
62
+ status = payload[:status]
63
+ if status.nil? && payload[:exception].present?
64
+ exception_class_name = payload[:exception].first
65
+ status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
66
+ end
67
+ status
68
+ end
69
+
70
+
71
+ ActiveSupport::Notifications.subscribe 'request.action_dispatch' do |*args|
72
+ x = args.extract_options!
73
+ request = x[:request]
74
+
75
+ data = Thread.current[:logdata] || {}
76
+ data[:remote_ip] = request.remote_ip
77
+ data[:path] = request.filtered_path
78
+
79
+ if (ac = request.env["action_controller.instance"]) &&
80
+ (response = ac.response) &&
81
+ (body = response.body) &&
82
+ body.present? &&
83
+ body =~ /\A\{"_api_error"/
84
+ data[:_api_error] = JSON.parse(body)['_api_error']
85
+ end
86
+
87
+ ex = request.env["action_dispatch.exception"]
88
+ if ex
89
+ if data[:status] == 404
90
+ data[:path] = request.env["REQUEST_PATH"]
91
+ else
92
+ # We might want to send an email here - exceptions in production
93
+ # should be taken seriously
94
+ data[:exception_message] = ex.message
95
+ data[:exception_backtrace] = ex.backtrace.to_json
96
+ end
97
+ end
98
+
99
+ if data[:status] >= 500
100
+ Rails.logger.fatal data
101
+ elsif data[:status] >= 400
102
+ Rails.logger.error data
103
+ else
104
+ Rails.logger.info data
105
+ end
106
+ end
107
+
@@ -95,12 +95,4 @@ class OceanSetupGenerator < Rails::Generators::NamedBase #:nodoc: all
95
95
  "Rails.logger = ZeromqLogger.new\n\n"
96
96
  end
97
97
 
98
- def turn_off_view_logging_in_production
99
- application(nil, env: "production") do
100
- "# We don't want to see view render lines in production.
101
- config.action_view.logger = nil
102
- "
103
- end
104
- end
105
-
106
98
  end
@@ -38,7 +38,6 @@ class SelectiveRackLogger < Rails::Rack::Logger
38
38
 
39
39
  instrumenter = ActiveSupport::Notifications.instrumenter
40
40
  instrumenter.start 'request.action_dispatch', request: request
41
- #logger.info started_request_message(request)
42
41
  resp = @app.call(env)
43
42
  resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) }
44
43
  resp
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "1.29.4"
2
+ VERSION = "1.29.5"
3
3
  end
@@ -75,15 +75,14 @@ class ZeromqLogger
75
75
  def add(level, msg)
76
76
  return true if level < @level
77
77
  return true if msg.blank? # Don't send
78
- #puts "Adding #{level} #{msg}"
79
- milliseconds = (Time.now.utc.to_f * 1000).to_i
80
- data = { timestamp: milliseconds,
81
- ip: @ip,
78
+ data = { ip: @ip,
82
79
  pid: Process.pid,
83
80
  service: APP_NAME,
84
- level: level,
85
- msg: msg.kind_of?(String) ? msg : msg.inspect
81
+ level: level
86
82
  }
83
+ data = data.merge msg if msg.is_a?(Hash)
84
+ data[:msg] = msg if msg.is_a?(String)
85
+ data[:timestamp] = (Time.now.utc.to_f * 1000).to_i unless data[:timestamp]
87
86
  @logger.log data
88
87
  true
89
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.4
4
+ version: 1.29.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-09 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -252,6 +252,7 @@ files:
252
252
  - config/initializers/api_constants.rb
253
253
  - config/initializers/aws_constants.rb
254
254
  - config/initializers/ocean_constants.rb
255
+ - config/initializers/one_line_logging.rb
255
256
  - config/initializers/zeromq_logger.rb
256
257
  - config/routes.rb
257
258
  - lib/generators/ocean_scaffold/USAGE