logstasher 2.1.3 → 3.0.0
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 +4 -4
- data/lib/logstasher/action_view/log_subscriber.rb +2 -1
- data/lib/logstasher/active_support/log_subscriber.rb +1 -0
- data/lib/logstasher/custom_fields.rb +4 -1
- data/lib/logstasher/rails_ext/action_controller/base.rb +6 -1
- data/lib/logstasher/rails_ext/action_controller/metal/instrumentation.rb +6 -1
- data/lib/logstasher/railtie.rb +17 -16
- data/lib/logstasher/version.rb +1 -1
- data/lib/logstasher.rb +33 -5
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8c812ac81d2e0aa6cd314f3325e7e875ccc746752a2539ba46b13ec273faa4f6
|
|
4
|
+
data.tar.gz: 8e14621d9afaf65e07accab9b27009ff3a3b9502a2b0e1d8f1d81e99570d68e3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 570318f5ceae39043b9c4a1085a056939d228d5133f775698b6d3d1e713fbaeb11f48c97fcd2c95bfdd641a9c71558f4952b8dcfd37833f574413b992dd6a8cb
|
|
7
|
+
data.tar.gz: 2172c27d4a0fff550cc0f911110e97cd4fed232fc108c7d2add2917a6af19be0e5801dd96cdc2c5411264d13cba8082b253038e8ecc0923ff07993007968edb2
|
|
@@ -4,7 +4,10 @@ module LogStasher
|
|
|
4
4
|
module CustomFields
|
|
5
5
|
module LogSubscriber
|
|
6
6
|
def extract_custom_fields(data)
|
|
7
|
-
|
|
7
|
+
# Don't mutate the original payload; slice the requested fields instead
|
|
8
|
+
fields = CustomFields.custom_fields
|
|
9
|
+
return {} if fields.empty?
|
|
10
|
+
data.respond_to?(:slice) ? data.slice(*fields) : fields.each_with_object({}) { |k, h| h[k] = data[k] if data.key?(k) }
|
|
8
11
|
end
|
|
9
12
|
end
|
|
10
13
|
|
|
@@ -18,7 +18,12 @@ module LogStasher
|
|
|
18
18
|
def append_info_to_payload(payload) #:nodoc:
|
|
19
19
|
LogStasher.add_default_fields_to_payload(payload, request)
|
|
20
20
|
if respond_to?(:logstasher_add_custom_fields_to_request_context)
|
|
21
|
-
|
|
21
|
+
# Collect custom fields into a temporary hash, then merge into both
|
|
22
|
+
# the per-request context and the controller payload.
|
|
23
|
+
_fields = {}
|
|
24
|
+
logstasher_add_custom_fields_to_request_context(_fields)
|
|
25
|
+
LogStasher.request_context.merge!(_fields)
|
|
26
|
+
payload.merge!(_fields)
|
|
22
27
|
end
|
|
23
28
|
|
|
24
29
|
if respond_to?(:logstasher_add_custom_fields_to_payload)
|
|
@@ -26,7 +26,12 @@ module ActionController
|
|
|
26
26
|
|
|
27
27
|
ActiveSupport::Notifications.instrument('process_action.action_controller', raw_payload) do |payload|
|
|
28
28
|
if respond_to?(:logstasher_add_custom_fields_to_request_context)
|
|
29
|
-
|
|
29
|
+
# Collect custom fields in a temporary hash then merge into both
|
|
30
|
+
# request context and the event payload to satisfy specs.
|
|
31
|
+
_fields = {}
|
|
32
|
+
logstasher_add_custom_fields_to_request_context(_fields)
|
|
33
|
+
LogStasher.request_context.merge!(_fields)
|
|
34
|
+
payload.merge!(_fields)
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
if respond_to?(:logstasher_add_custom_fields_to_payload)
|
data/lib/logstasher/railtie.rb
CHANGED
|
@@ -6,6 +6,21 @@ require 'action_controller/log_subscriber'
|
|
|
6
6
|
require 'socket'
|
|
7
7
|
|
|
8
8
|
module LogStasher
|
|
9
|
+
def default_source
|
|
10
|
+
case RUBY_PLATFORM
|
|
11
|
+
when /darwin/
|
|
12
|
+
# NOTE: MacOS Sierra and later are setting `.local`
|
|
13
|
+
# hostnames that even as real hostnames without the `.local` part,
|
|
14
|
+
# are still unresolvable. One reliable way to get an IP is to
|
|
15
|
+
# get all available IP address lists and use the first one.
|
|
16
|
+
# This will always be `127.0.0.1`.
|
|
17
|
+
address_info = Socket.ip_address_list.first
|
|
18
|
+
address_info&.ip_address
|
|
19
|
+
else
|
|
20
|
+
IPSocket.getaddress(Socket.gethostname)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
9
24
|
class Railtie < Rails::Railtie
|
|
10
25
|
config.logstasher = ::ActiveSupport::OrderedOptions.new
|
|
11
26
|
config.logstasher.enabled = false
|
|
@@ -16,6 +31,7 @@ module LogStasher
|
|
|
16
31
|
config.logstasher.record_enabled = false
|
|
17
32
|
config.logstasher.view_enabled = true
|
|
18
33
|
config.logstasher.job_enabled = true
|
|
34
|
+
config.logstasher.source = LogStasher.default_source
|
|
19
35
|
|
|
20
36
|
# Try loading the config/logstasher.yml if present
|
|
21
37
|
env = Rails.env.to_sym || :development
|
|
@@ -37,7 +53,7 @@ module LogStasher
|
|
|
37
53
|
LogStasher.setup_before(app.config.logstasher) if app.config.logstasher.enabled
|
|
38
54
|
end
|
|
39
55
|
|
|
40
|
-
initializer :
|
|
56
|
+
initializer :logstasher_after_init do
|
|
41
57
|
config.after_initialize do
|
|
42
58
|
LogStasher.setup(config.logstasher) if config.logstasher.enabled
|
|
43
59
|
end
|
|
@@ -48,21 +64,6 @@ module LogStasher
|
|
|
48
64
|
end
|
|
49
65
|
end
|
|
50
66
|
|
|
51
|
-
def default_source
|
|
52
|
-
case RUBY_PLATFORM
|
|
53
|
-
when /darwin/
|
|
54
|
-
# NOTE: MacOS Sierra and later are setting `.local`
|
|
55
|
-
# hostnames that even as real hostnames without the `.local` part,
|
|
56
|
-
# are still unresolvable. One reliable way to get an IP is to
|
|
57
|
-
# get all available IP address lists and use the first one.
|
|
58
|
-
# This will always be `127.0.0.1`.
|
|
59
|
-
address_info = Socket.ip_address_list.first
|
|
60
|
-
address_info&.ip_address
|
|
61
|
-
else
|
|
62
|
-
IPSocket.getaddress(Socket.gethostname)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
67
|
def process_config(config, yml_config)
|
|
67
68
|
# Enable the logstasher logs for the current environment
|
|
68
69
|
config.enabled = yml_config[:enabled] if yml_config.key? :enabled
|
data/lib/logstasher/version.rb
CHANGED
data/lib/logstasher.rb
CHANGED
|
@@ -47,10 +47,24 @@ module LogStasher
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def unsubscribe(component, subscriber)
|
|
50
|
+
# Use Rails' built-in detach mechanism when available (Rails 5.1+).
|
|
51
|
+
# detach_from is a class method, so we get the class first.
|
|
52
|
+
klass = subscriber.is_a?(Class) ? subscriber : subscriber.class
|
|
53
|
+
if klass.respond_to?(:detach_from)
|
|
54
|
+
klass.detach_from(component)
|
|
55
|
+
return
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Fallback for older Rails versions without detach_from.
|
|
50
59
|
events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
|
|
51
60
|
events.each do |event|
|
|
52
61
|
::ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
|
|
53
|
-
|
|
62
|
+
begin
|
|
63
|
+
delegate = listener.instance_variable_get('@delegate')
|
|
64
|
+
rescue StandardError
|
|
65
|
+
delegate = nil
|
|
66
|
+
end
|
|
67
|
+
::ActiveSupport::Notifications.unsubscribe(listener) if delegate == subscriber
|
|
54
68
|
end
|
|
55
69
|
end
|
|
56
70
|
end
|
|
@@ -71,8 +85,15 @@ module LogStasher
|
|
|
71
85
|
LogStasher::CustomFields.add(*LogStasher.store.keys)
|
|
72
86
|
instance_exec(fields, &block)
|
|
73
87
|
end
|
|
74
|
-
::ActionController::
|
|
75
|
-
|
|
88
|
+
if defined?(::ActionController::Base) || defined?(::ActionController::Metal)
|
|
89
|
+
::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block) if defined?(::ActionController::Metal)
|
|
90
|
+
::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block) if defined?(::ActionController::Base)
|
|
91
|
+
else
|
|
92
|
+
::ActiveSupport.on_load(:action_controller) do
|
|
93
|
+
::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block)
|
|
94
|
+
::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
76
97
|
end
|
|
77
98
|
|
|
78
99
|
def add_custom_fields_to_request_context(&block)
|
|
@@ -80,8 +101,15 @@ module LogStasher
|
|
|
80
101
|
instance_exec(fields, &block)
|
|
81
102
|
LogStasher::CustomFields.add(*fields.keys)
|
|
82
103
|
end
|
|
83
|
-
::ActionController::
|
|
84
|
-
|
|
104
|
+
if defined?(::ActionController::Base) || defined?(::ActionController::Metal)
|
|
105
|
+
::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block) if defined?(::ActionController::Metal)
|
|
106
|
+
::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block) if defined?(::ActionController::Base)
|
|
107
|
+
else
|
|
108
|
+
::ActiveSupport.on_load(:action_controller) do
|
|
109
|
+
::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block)
|
|
110
|
+
::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
85
113
|
end
|
|
86
114
|
|
|
87
115
|
def add_default_fields_to_request_context(request)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: logstasher
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shadab Ahmed
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-11-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '7.0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '7.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: request_store
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '7.0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '7.0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: rspec
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
120
|
- !ruby/object:Gem::Version
|
|
121
121
|
version: '0'
|
|
122
122
|
requirements: []
|
|
123
|
-
rubygems_version: 3.
|
|
123
|
+
rubygems_version: 3.4.19
|
|
124
124
|
signing_key:
|
|
125
125
|
specification_version: 4
|
|
126
126
|
summary: Awesome rails logs
|