Navigation Menu

Skip to content

Commit

Permalink
out: Use log method instead of $log global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0920 committed Apr 12, 2017
1 parent f0ec06a commit e4c31bc
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions lib/fluent/plugin/out_groonga.rb
Expand Up @@ -109,9 +109,9 @@ def write(chunk)
def create_client(protocol)
case protocol
when :http, :gqtp
NetworkClient.new(protocol)
NetworkClient.new(protocol, self)
when :command
CommandClient.new
CommandClient.new(self)
end
end

Expand Down Expand Up @@ -610,9 +610,10 @@ class NetworkClient < BaseClient
config_param :host, :string, :default => nil
config_param :port, :integer, :default => nil

def initialize(protocol)
def initialize(protocol, output_plugin)
super()
@protocol = protocol
@output_plugin = output_plugin
end

def start
Expand All @@ -634,17 +635,17 @@ def execute(name, arguments={})
begin
response = @client.execute(command)
rescue Groonga::Client::Error
$log.error("[output][groonga][error]",
:protocol => @protocol,
:host => @host,
:port => @port,
:command_name => name)
@output_plugin.log.error("[output][groonga][error]",
:protocol => @protocol,
:host => @host,
:port => @port,
:command_name => name)
raise
end
unless response.success?
$log.error("[output][groonga][error]",
:status_code => response.status_code,
:message => response.message)
@output_plugin.log.error("[output][groonga][error]",
:status_code => response.status_code,
:message => response.message)
end
response
end
Expand All @@ -659,8 +660,9 @@ class CommandClient < BaseClient
Shellwords.split(value)
end

def initialize
super
def initialize(output_plugin)
super()
@output_plugin = output_plugin
end

def configure(conf)
Expand Down Expand Up @@ -747,14 +749,14 @@ def read_output(context)
end

unless output_message.empty?
$log.debug("[output][groonga][output]",
:context => context,
:message => output_message)
@output_plugin.log.debug("[output][groonga][output]",
:context => context,
:message => output_message)
end
unless error_message.empty?
$log.error("[output][groonga][error]",
:context => context,
:message => error_message)
@output_plugin.log.error("[output][groonga][error]",
:context => context,
:message => error_message)
end
end
end
Expand Down

0 comments on commit e4c31bc

Please sign in to comment.