Skip to content

Commit 0d2d180

Browse files
Ensure that default_source is defined before it gets invoked on Railtie class load (#170)
1 parent ee918a7 commit 0d2d180

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/logstasher/railtie.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
require 'socket'
77

88
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+
924
class Railtie < Rails::Railtie
1025
config.logstasher = ::ActiveSupport::OrderedOptions.new
1126
config.logstasher.enabled = false
@@ -49,21 +64,6 @@ def rack_cache_hashlike?(app)
4964
end
5065
end
5166

52-
def default_source
53-
case RUBY_PLATFORM
54-
when /darwin/
55-
# NOTE: MacOS Sierra and later are setting `.local`
56-
# hostnames that even as real hostnames without the `.local` part,
57-
# are still unresolvable. One reliable way to get an IP is to
58-
# get all available IP address lists and use the first one.
59-
# This will always be `127.0.0.1`.
60-
address_info = Socket.ip_address_list.first
61-
address_info&.ip_address
62-
else
63-
IPSocket.getaddress(Socket.gethostname)
64-
end
65-
end
66-
6767
def process_config(config, yml_config)
6868
# Enable the logstasher logs for the current environment
6969
config.enabled = yml_config[:enabled] if yml_config.key? :enabled

0 commit comments

Comments
 (0)