diff --git a/lib/fluent/log.rb b/lib/fluent/log.rb index e789b394be..67f0a37375 100644 --- a/lib/fluent/log.rb +++ b/lib/fluent/log.rb @@ -174,6 +174,7 @@ def dup clone.format = @format clone.time_format = @time_format clone.log_event_enabled = @log_event_enabled + clone.force_stacktrace_level(@forced_stacktrace_level) # optional headers/attrs are not copied, because new PluginLogger should have another one of it clone end @@ -652,6 +653,9 @@ def initialize(logger) if logger.instance_variable_defined?(:@suppress_repeated_stacktrace) @suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace) end + if logger.instance_variable_defined?(:@forced_stacktrace_level) + @forced_stacktrace_level = logger.instance_variable_get(:@forced_stacktrace_level) + end if logger.instance_variable_defined?(:@ignore_repeated_log_interval) @ignore_repeated_log_interval = logger.instance_variable_get(:@ignore_repeated_log_interval) end diff --git a/test/test_log.rb b/test/test_log.rb index f2cf45533c..f346d175c9 100644 --- a/test/test_log.rb +++ b/test/test_log.rb @@ -811,14 +811,6 @@ def test_initialize assert_equal(logger, @logger) end - def test_level - log = Fluent::PluginLogger.new(@logger) - assert_equal(log.level, @logger.level) - log.level = "fatal" - assert_equal(Fluent::Log::LEVEL_FATAL, log.level) - assert_equal(Fluent::Log::LEVEL_TRACE, @logger.level) - end - def test_enable_color log = Fluent::PluginLogger.new(@logger) log.enable_color(true) @@ -864,6 +856,45 @@ def test_log_types @logger.fatal :worker0, "fatal log 6" end + sub_test_case "take over the parent logger" do + def test_level + log = Fluent::PluginLogger.new(@logger) + assert_equal(log.level, @logger.level) + log.level = "fatal" + assert_equal(Fluent::Log::LEVEL_FATAL, log.level) + assert_equal(Fluent::Log::LEVEL_TRACE, @logger.level) + end + + def test_options + parent_log = Fluent::Log.new( + ServerEngine::DaemonLogger.new( + @log_device, + log_level: ServerEngine::DaemonLogger::INFO, + ), + suppress_repeated_stacktrace: true, + ignore_repeated_log_interval: 10, + ignore_same_log_interval: 10, + ) + parent_log.force_stacktrace_level(Fluent::Log::LEVEL_INFO) + + log = Fluent::PluginLogger.new(parent_log) + assert_equal( + [ + true, + Fluent::Log::LEVEL_INFO, + 10, + 10, + ], + [ + log.instance_variable_get(:@suppress_repeated_stacktrace), + log.instance_variable_get(:@forced_stacktrace_level), + log.instance_variable_get(:@ignore_repeated_log_interval), + log.instance_variable_get(:@ignore_same_log_interval), + ] + ) + end + end + sub_test_case "supervisor process type" do setup do dl_opts = {} @@ -1114,6 +1145,49 @@ def test_terminate mock(plugin.log).reset plugin.terminate end + + sub_test_case "take over the parent logger" do + def setup + super + + begin + saved_global_logger = $log + $log = Fluent::Log.new( + ServerEngine::DaemonLogger.new( + Fluent::Test::DummyLogDevice.new, + log_level: ServerEngine::DaemonLogger::INFO, + ), + suppress_repeated_stacktrace: true, + ignore_repeated_log_interval: 10, + ignore_same_log_interval: 10, + ) + $log.force_stacktrace_level(Fluent::Log::LEVEL_INFO) + yield + ensure + $log = saved_global_logger + end + end + + def test_options + plugin = DummyPlugin.new + plugin.configure(Fluent::Config::Element.new("input", "", {"@id" => "foo"}, [])) + + assert_equal( + [ + true, + Fluent::Log::LEVEL_INFO, + 10, + 10, + ], + [ + plugin.log.instance_variable_get(:@suppress_repeated_stacktrace), + plugin.log.instance_variable_get(:@forced_stacktrace_level), + plugin.log.instance_variable_get(:@ignore_repeated_log_interval), + plugin.log.instance_variable_get(:@ignore_same_log_interval), + ] + ) + end + end end class LogDeviceIOTest < Test::Unit::TestCase