Skip to content

Commit aa7d3ef

Browse files
committed
Add connect_timeout / resolve_timeout option
Signed-off-by: Shizuo Fujita <[email protected]>
1 parent 936362c commit aa7d3ef

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ Use nonblocking write(`IO#write_nonblock`) instead of normal write(`IO#write`).
148148

149149
If `false`, `Logger#post` raises an error when nonblocking write gets `EAGAIN` (i.e. `use_nonblock` must be `true`, otherwise this will have no effect). Default: `true`
150150

151+
#### connect_timeout (Integer)
152+
153+
Specify timeout in seconds from connecting. Default: `nil`
154+
155+
#### resolve_timeout (Integer)
156+
157+
Specify timeout in seconds from when the hostname resolution starts. Default: `nil`
158+
151159
#### buffer_overflow_handler (Proc)
152160

153161
Pass callback for handling buffer overflow with pending data. See "Buffer overflow" section.

fluent-logger.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Gem::Specification.new do |gem|
2121
gem.require_paths = ['lib']
2222
gem.license = "Apache-2.0"
2323

24+
gem.required_ruby_version = '>= 2.7'
25+
2426
gem.add_dependency "msgpack", ">= 1.0.0", "< 2"
2527

2628
# logger gem that isn't default gems as of Ruby 3.5

lib/fluent/logger/fluent_logger.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def initialize(tag_prefix = nil, *args)
115115
@wait_writeable = true
116116
@wait_writeable = options[:wait_writeable] if options.key?(:wait_writeable)
117117

118+
@connect_timeout = options[:connect_timeout]
119+
@resolv_timeout = options[:resolv_timeout]
120+
118121
@last_error = {}
119122

120123
begin
@@ -170,7 +173,7 @@ def create_socket!
170173
if @socket_path
171174
@con = UNIXSocket.new(@socket_path)
172175
else
173-
@con = TCPSocket.new(@host, @port)
176+
@con = Socket.tcp(@host, @port, connect_timeout: @connect_timeout, resolv_timeout: @resolv_timeout)
174177
if @tls_options
175178
context = OpenSSL::SSL::SSLContext.new
176179
if @tls_options[:insecure]

0 commit comments

Comments
 (0)