Skip to content

Commit

Permalink
Fix option log_level
Browse files Browse the repository at this point in the history
Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Feb 20, 2023
1 parent 41678bf commit dd0f872
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/fluent/command/fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@
}

op.on('-v', '--verbose', "increase verbose level (-v: debug, -vv: trace)", TrueClass) {|b|
if b
cmd_opts[:log_level] = [default_opts[:log_level] - 1, Fluent::Log::LEVEL_TRACE].max
end
return unless b
cur_level = cmd_opts.fetch(:log_level, default_opts[:log_level])
cmd_opts[:log_level] = [cur_level - 1, Fluent::Log::LEVEL_TRACE].max
}

op.on('-q', '--quiet', "decrease verbose level (-q: warn, -qq: error)", TrueClass) {|b|
if b
cmd_opts[:log_level] = [default_opts[:log_level] + 1, Fluent::Log::LEVEL_ERROR].min
end
return unless b
cur_level = cmd_opts.fetch(:log_level, default_opts[:log_level])
cmd_opts[:log_level] = [cur_level + 1, Fluent::Log::LEVEL_TRACE].max
}

op.on('--suppress-config-dump', "suppress config dumping when fluentd starts", TrueClass) {|b|
Expand Down
61 changes: 61 additions & 0 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1160,4 +1160,65 @@ def multi_workers_ready?; true; end
"shared socket for multiple workers is disabled",)
end
end

sub_test_case 'log_level by command line option' do
test 'info' do
conf = ""
conf_path = create_conf_file('empty.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path),
"[info]",
patterns_not_match: ["[debug]"])
end

test 'debug' do
conf = ""
conf_path = create_conf_file('empty.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path, "-v"),
"[debug]",
patterns_not_match: ["[trace]"])
end

test 'trace' do
conf = <<CONF
<source>
@type sample
tag test
</source>
CONF
conf_path = create_conf_file('sample.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path, "-vv"),
"[trace]",)
end

test 'warn' do
conf = <<CONF
<source>
@type sample
tag test
</source>
CONF
conf_path = create_conf_file('sample.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path, "-q"),
"[warn]",
patterns_not_match: ["[info]"])
end

test 'error' do
conf = <<CONF
<source>
@type plugin_not_found
tag test
</source>
CONF
conf_path = create_conf_file('plugin_not_found.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path, "-qq"),
"[error]",
patterns_not_match: ["[warn]"])
end
end
end

0 comments on commit dd0f872

Please sign in to comment.