Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log_level handling in <system>. fix #1499 #1501

Merged
merged 2 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/fluent/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ def attach(supervisor)
next # doesn't exist in command line options
when :emit_error_log_interval
system.emit_error_log_interval = @suppress_interval if @suppress_interval
when :log_level
ll_value = instance_variable_get("@log_level")
# info level can't be specified via command line option.
# log_level is info here, it is default value and <system>'s log_level should be applied if exists.
if ll_value != Fluent::Log::LEVEL_INFO
system.log_level = ll_value
end
else
next unless instance_variable_defined?("@#{param}")
supervisor_value = instance_variable_get("@#{param}")
Expand Down
42 changes: 36 additions & 6 deletions test/config/test_system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ def initalize
end

class FakeSupervisor
attr_writer :log_level

def initialize
@workers = nil
@root_dir = nil
@log = FakeLoggerInitializer.new
@log_level = nil
@log_level = Fluent::Log::LEVEL_INFO
@suppress_interval = nil
@suppress_config_dump = nil
@suppress_repeated_stacktrace = nil
Expand Down Expand Up @@ -55,7 +57,7 @@ def parse_text(text)
assert_nil(sc.without_source)
assert_equal(1, s.instance_variable_get(:@workers))
assert_nil(s.instance_variable_get(:@root_dir))
assert_nil(s.instance_variable_get(:@log_level))
assert_equal(Fluent::Log::LEVEL_INFO, s.instance_variable_get(:@log_level))
assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace))
assert_nil(s.instance_variable_get(:@emit_error_log_interval))
assert_nil(s.instance_variable_get(:@suppress_config_dump))
Expand Down Expand Up @@ -99,7 +101,7 @@ def parse_text(text)
sc.apply(s)
assert_equal(1, s.instance_variable_get(:@workers))
assert_nil(s.instance_variable_get(:@root_dir))
assert_nil(s.instance_variable_get(:@log_level))
assert_equal(Fluent::Log::LEVEL_INFO, s.instance_variable_get(:@log_level))
assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace))
assert_nil(s.instance_variable_get(:@emit_error_log_interval))
assert_nil(s.instance_variable_get(:@suppress_config_dump))
Expand All @@ -109,16 +111,43 @@ def parse_text(text)
assert_nil(s.instance_variable_get(:@dir_permission))
end

test 'log_level' do
data('trace' => Fluent::Log::LEVEL_TRACE,
'debug' => Fluent::Log::LEVEL_DEBUG,
'info' => Fluent::Log::LEVEL_INFO,
'warn' => Fluent::Log::LEVEL_WARN,
'error' => Fluent::Log::LEVEL_ERROR,
'fatal' => Fluent::Log::LEVEL_FATAL)
test 'log_level is applied when log_level related command line option is not passed' do |level|
conf = parse_text(<<-EOS)
<system>
log_level #{Fluent::Log::LEVEL_TEXT[level]}
</system>
EOS
s = FakeSupervisor.new
sc = Fluent::SystemConfig.new(conf)
sc.attach(s)
sc.apply(s)
assert_equal(level, s.instance_variable_get("@log").level)
end

# info is removed because info level can't be specified via command line
data('trace' => Fluent::Log::LEVEL_TRACE,
'debug' => Fluent::Log::LEVEL_DEBUG,
'warn' => Fluent::Log::LEVEL_WARN,
'error' => Fluent::Log::LEVEL_ERROR,
'fatal' => Fluent::Log::LEVEL_FATAL)
test 'log_level is ignored when log_level related command line option is passed' do |level|
conf = parse_text(<<-EOS)
<system>
log_level warn
log_level info
</system>
EOS
s = FakeSupervisor.new
s.log_level = level
sc = Fluent::SystemConfig.new(conf)
sc.attach(s)
sc.apply(s)
assert_equal(Fluent::Log::LEVEL_WARN, s.instance_variable_get("@log").level)
assert_equal(level, s.instance_variable_get("@log").level)
end

test 'process global overridable variables' do
Expand All @@ -130,6 +159,7 @@ def parse_text(text)
EOS
s = FakeSupervisor.new
sc = Fluent::SystemConfig.new(conf)
sc.attach(s)
sc.apply(s)
assert_equal(0655, s.instance_variable_get(:@file_permission))
assert_equal(0765, s.instance_variable_get(:@dir_permission))
Expand Down