Skip to content

Commit f6f002e

Browse files
authored
rubocop: use plugin scope logger (#5028)
**Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: * Delay string interpolation for log.debug * Use plugin scope logger instead of global scope $log This issue was found by the following rubocop: ``` Lint/FluentdPluginLogScope: AssumeConfigLogLevel: 'info' Exclude: - 'lib/fluent/*.rb' - 'lib/fluent/compat/*.rb' Enabled: true ``` **Docs Changes**: N/A **Release Note**: N/A Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
1 parent 11e69f2 commit f6f002e

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

lib/fluent/plugin/in_monitor_agent.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def self.call(_req)
204204
def start
205205
super
206206

207-
log.debug "listening monitoring http server on http://#{@bind}:#{@port}/api/plugins for worker#{fluentd_worker_id}"
207+
log.debug { "listening monitoring http server on http://#{@bind}:#{@port}/api/plugins for worker#{fluentd_worker_id}" }
208208
api_handler = APIHandler.new(self)
209209
http_server_create_http_server(:in_monitor_http_server_helper, addr: @bind, port: @port, logger: log, default_app: NotFoundJson) do |serv|
210210
serv.get('/api/plugins') { |req| api_handler.plugins_ltsv(req) }
@@ -214,7 +214,7 @@ def start
214214
end
215215

216216
if @tag
217-
log.debug "tag parameter is specified. Emit plugins info to '#{@tag}'"
217+
log.debug { "tag parameter is specified. Emit plugins info to '#{@tag}'" }
218218

219219
opts = {with_config: false, with_retry: false}
220220
timer_execute(:in_monitor_agent_emit, @emit_interval, repeat: true) {

lib/fluent/plugin/in_tail.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ def configure(conf)
178178
if @follow_inodes
179179
raise Fluent::ConfigError, "Can't follow inodes without pos_file configuration parameter"
180180
end
181-
$log.warn "'pos_file PATH' parameter is not set to a 'tail' source."
182-
$log.warn "this parameter is highly recommended to save the position to resume tailing."
181+
log.warn "'pos_file PATH' parameter is not set to a 'tail' source."
182+
log.warn "this parameter is highly recommended to save the position to resume tailing."
183183
end
184184

185185
configure_tag
@@ -369,7 +369,7 @@ def expand_paths_raw
369369
false
370370
end
371371
rescue Errno::ENOENT, Errno::EACCES
372-
log.debug("#{p} is missing after refresh file list")
372+
log.debug { "#{p} is missing after refresh file list" }
373373
false
374374
end
375375
}
@@ -405,7 +405,7 @@ def expand_paths
405405
hash[target_info.path] = target_info
406406
end
407407
rescue Errno::ENOENT, Errno::EACCES => e
408-
$log.warn "expand_paths: stat() for #{path} failed with #{e.class.name}. Skip file."
408+
log.warn "expand_paths: stat() for #{path} failed with #{e.class.name}. Skip file."
409409
end
410410
}
411411
hash
@@ -523,7 +523,7 @@ def construct_watcher(target_info)
523523
begin
524524
target_info.ino = Fluent::FileWrapper.stat(path).ino
525525
rescue Errno::ENOENT, Errno::EACCES
526-
$log.warn "stat() for #{path} failed. Continuing without tailing it."
526+
log.warn "stat() for #{path} failed. Continuing without tailing it."
527527
return
528528
end
529529

lib/fluent/plugin/out_stream.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class TcpOutput < StreamOutput
9292

9393
def initialize
9494
super
95-
$log.warn "'tcp' output is obsoleted and will be removed. Use 'forward' instead."
96-
$log.warn "see 'forward' section in https://docs.fluentd.org/ for the high-availability configuration."
95+
log.warn "'tcp' output is obsoleted and will be removed. Use 'forward' instead."
96+
log.warn "see 'forward' section in https://docs.fluentd.org/ for the high-availability configuration."
9797
end
9898

9999
config_param :port, :integer, default: LISTEN_PORT
@@ -114,7 +114,7 @@ class UnixOutput < StreamOutput
114114

115115
def initialize
116116
super
117-
$log.warn "'unix' output is obsoleted and will be removed."
117+
log.warn "'unix' output is obsoleted and will be removed."
118118
end
119119

120120
config_param :path, :string

test/plugin/test_in_tail.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,8 +2553,8 @@ def test_ENOENT_error_after_setup_watcher
25532553
assert_nothing_raised do
25542554
d.run(shutdown: false) {}
25552555
end
2556-
assert($log.out.logs.any?{|log| log.include?("stat() for #{path} failed. Continuing without tailing it.\n") },
2557-
$log.out.logs.join("\n"))
2556+
assert(d.logs.any?{|log| log.include?("stat() for #{path} failed. Continuing without tailing it.\n") },
2557+
d.logs.join("\n"))
25582558
ensure
25592559
d.instance_shutdown if d&.instance
25602560
end
@@ -2579,8 +2579,8 @@ def test_EACCES_error_after_setup_watcher
25792579
assert_nothing_raised do
25802580
d.run(shutdown: false) {}
25812581
end
2582-
assert($log.out.logs.any?{|log| log.include?("stat() for #{path} failed. Continuing without tailing it.\n") },
2583-
$log.out.logs.join("\n"))
2582+
assert(d.logs.any?{|log| log.include?("stat() for #{path} failed. Continuing without tailing it.\n") },
2583+
d.logs.join("\n"))
25842584
end
25852585
ensure
25862586
d.instance_shutdown if d&.instance
@@ -2603,7 +2603,7 @@ def test_EACCES
26032603
assert_nothing_raised do
26042604
d.run(shutdown: false) {}
26052605
end
2606-
assert($log.out.logs.any?{|log| log.include?("expand_paths: stat() for #{path} failed with Errno::EACCES. Skip file.\n") })
2606+
assert(d.logs.any?{|log| log.include?("expand_paths: stat() for #{path} failed with Errno::EACCES. Skip file.\n") })
26072607
ensure
26082608
d.instance_shutdown if d&.instance
26092609
end

0 commit comments

Comments
 (0)