Skip to content

Commit

Permalink
Fix logging to stdout and respect reconnect_interval (#43)
Browse files Browse the repository at this point in the history
Removed Stud::try to fix logging to stdout and respect `reconnect_interval` in connection retry
Fixed: #12
  • Loading branch information
kaisecheng authored Feb 7, 2022
1 parent 57c8797 commit 12ca0de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.0.1
- Fixed logging fail retry to stdout [#43](https://github.com/logstash-plugins/logstash-output-tcp/pull/43)
- Fixed to use `reconnect_interval` when establish a connection

## 6.0.0
- Removed obsolete field `message_format`

Expand Down
9 changes: 6 additions & 3 deletions lib/logstash/outputs/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ def register

private
def connect
Stud::try do
begin
client_socket = TCPSocket.new(@host, @port)
if @ssl_enable
client_socket = OpenSSL::SSL::SSLSocket.new(client_socket, @ssl_context)
begin
client_socket.connect
rescue OpenSSL::SSL::SSLError => ssle
@logger.error("SSL Error", :exception => ssle,
:backtrace => ssle.backtrace)
@logger.error("SSL Error", :exception => ssle, :backtrace => ssle.backtrace)
# NOTE(mrichar1): Hack to prevent hammering peer
sleep(5)
raise
Expand All @@ -190,6 +189,10 @@ def connect
client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
@logger.debug("Opened connection", :client => "#{client_socket.peer}")
return client_socket
rescue StandardError => e
@logger.error("Failed to connect: #{e.message}", :exception => e.class, :backtrace => e.backtrace)
sleep @reconnect_interval
retry
end
end # def connect

Expand Down
2 changes: 1 addition & 1 deletion logstash-output-tcp.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-output-tcp'
s.version = '6.0.0'
s.version = '6.0.1'
s.licenses = ['Apache License (2.0)']
s.summary = "Writes events over a TCP socket"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down

0 comments on commit 12ca0de

Please sign in to comment.