lib/fluent/plugin/out_logentries.rb in fluent-plugin-logentries-0.0.4 vs lib/fluent/plugin/out_logentries.rb in fluent-plugin-logentries-0.0.5

- old
+ new

@@ -9,24 +9,25 @@ config_param :host, :string config_param :port, :integer, :default => 80 config_param :path, :string def configure(conf) - super @port = conf['port'] @host = conf['host'] @path = conf['path'] + + super end def start super end def shutdown - super - client.close + + super end def client @_socket ||= TCPSocket.new @host, @port end @@ -34,17 +35,18 @@ # This method is called when an event reaches to Fluentd. def format(tag, time, record) return [tag, record].to_msgpack end - # Scan a given directory for host tokens + # Scan a given directory for logentries tokens def generate_token(path) tokens = {} Dir[path << "*.token"].each do |file| key = File.basename(file, ".token") #remove path/extension from filename - tokens[key] = File.open(file, &:readline).gsub(/\r\n|\r|\n/, '') #read the first line and close it + #read the first line, remove unwanted char and close it + tokens[key] = File.open(file, &:readline).gsub(/\r\n|\r|\n/, '') end tokens end # returns the correct token to use for a given tag @@ -67,15 +69,15 @@ token = get_token(tag, tokens) next if token.nil? if record.has_key?("message") - send(record["message"] << ' ' << token) + send_logentries(record["message"] + ' ' + token) end end end - def send(data) + def send_logentries(data) retries = 0 begin client.puts data rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e if retries < 2