From bb002646dd073109380995cb645a51a3abd22ea9 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Sun, 12 Mar 2023 16:36:07 +0900 Subject: [PATCH] Fix command option `--quiet` Fix bug of: * #4064 * 8e9f46ae84e6fd603cf46c63cdef6f3b2334cca3 Signed-off-by: Daijiro Fukuda --- lib/fluent/command/fluentd.rb | 2 +- test/command/test_fluentd.rb | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/fluent/command/fluentd.rb b/lib/fluent/command/fluentd.rb index 33f19073e6..afa26553e5 100644 --- a/lib/fluent/command/fluentd.rb +++ b/lib/fluent/command/fluentd.rb @@ -166,7 +166,7 @@ op.on('-q', '--quiet', "decrease verbose level (-q: warn, -qq: error)", TrueClass) {|b| 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 + cmd_opts[:log_level] = [cur_level + 1, Fluent::Log::LEVEL_ERROR].min } op.on('--suppress-config-dump', "suppress config dumping when fluentd starts", TrueClass) {|b| diff --git a/test/command/test_fluentd.rb b/test/command/test_fluentd.rb index 0646974b4b..3628f9a542 100644 --- a/test/command/test_fluentd.rb +++ b/test/command/test_fluentd.rb @@ -1185,7 +1185,9 @@ def multi_workers_ready?; true; end patterns_not_match: ["[trace]"]) end - test 'trace' do + data("Trace" => "-vv") + data("Invalid low level should be treated as Trace level": "-vvv") + test 'trace' do |option| conf = < @type sample @@ -1194,7 +1196,7 @@ def multi_workers_ready?; true; end CONF conf_path = create_conf_file('sample.conf', conf) assert File.exist?(conf_path) - assert_log_matches(create_cmdline(conf_path, "-vv"), + assert_log_matches(create_cmdline(conf_path, option), "[trace]",) end @@ -1212,7 +1214,10 @@ def multi_workers_ready?; true; end patterns_not_match: ["[info]"]) end - test 'error' do + data("Error" => "-qq") + data("Fatal should be treated as Error level" => "-qqq") + data("Invalid high level should be treated as Error level": "-qqqq") + test 'error' do |option| conf = < @type plugin_not_found @@ -1221,7 +1226,7 @@ def multi_workers_ready?; true; end CONF conf_path = create_conf_file('plugin_not_found.conf', conf) assert File.exist?(conf_path) - assert_log_matches(create_cmdline(conf_path, "-qq"), + assert_log_matches(create_cmdline(conf_path, option), "[error]", patterns_not_match: ["[warn]"]) end