lib/magellan/log_funnel.rb in magellan-log-funnel-1.0.0 vs lib/magellan/log_funnel.rb in magellan-log-funnel-1.1.0

- old
+ new

@@ -1,10 +1,11 @@ # coding: utf-8 require "json" require "optparse" require "net/http" +require "fluent/logger" module Magellan class LogFunnel class Error < StandardError @@ -41,28 +42,36 @@ end o.order!(argv) end end + def connect_fluentd + @logger = Fluent::Logger::FluentLogger.new("worker_logs") + end + def now Time.now end + def stage_tag + @stage_tag ||= "#{@conf[:project]}.#{@conf[:stage]}" + end + def post_msg(msg) - Net::HTTP.post_form(@conf[:fluentd], json: JSON.generate({ - time: self.now.to_i, + @logger.post(stage_tag, { + time: self.now.to_f, project: @conf[:project], stage: @conf[:stage], version: @conf[:version], container: @conf[:container], message: msg - })) + }) end def run parse_options(@argv) - @conf[:fluentd] ||= URI("http://localhost:8888") - @conf[:fluentd].path = "/worker_logs.#{@conf[:project]}.#{@conf[:stage]}" + + connect_fluentd if @conf[:daemon] Process.daemon end