|
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 |
@@ -49,21 +64,6 @@ def rack_cache_hashlike?(app) |
49 | 64 | end |
50 | 65 | end |
51 | 66 |
|
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 | | - |
67 | 67 | def process_config(config, yml_config) |
68 | 68 | # Enable the logstasher logs for the current environment |
69 | 69 | config.enabled = yml_config[:enabled] if yml_config.key? :enabled |
|
0 commit comments