From 872369bea546de802f862fd21a660bee3b0db8cb Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 28 Nov 2023 14:29:22 -0500 Subject: [PATCH] Return the raw logger unless logger_class is present --- lib/vmdb/loggers.rb | 7 ++++++- spec/lib/vmdb/loggers_spec.rb | 8 +------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/vmdb/loggers.rb b/lib/vmdb/loggers.rb index b19cc4574cec..14c4ee2ff3e9 100644 --- a/lib/vmdb/loggers.rb +++ b/lib/vmdb/loggers.rb @@ -28,7 +28,7 @@ def self.apply_config(config) Vmdb::Plugins.each { |p| p.try(:apply_logger_config, config) } end - def self.create_logger(log_file_name, logger_class = ManageIQ::Loggers::Base) + def self.create_logger(log_file_name, logger_class = nil) if MiqEnvironment::Command.is_container? create_container_logger(log_file_name, logger_class) elsif MiqEnvironment::Command.supports_systemd? @@ -52,6 +52,7 @@ def self.create_logger(log_file_name, logger_class = ManageIQ::Loggers::Base) log_file = log_path_from_file(log_file) progname = progname_from_file(log_file) + logger_class ||= ManageIQ::Loggers::Base logger_class.new(log_file, :progname => progname) end @@ -62,6 +63,8 @@ def self.create_logger(log_file_name, logger_class = ManageIQ::Loggers::Base) progname = progname_from_file(log_file_name) logger.progname = progname + return logger if logger_class.nil? + create_wrapper_logger(progname, logger_class, logger) end @@ -72,6 +75,8 @@ def self.create_logger(log_file_name, logger_class = ManageIQ::Loggers::Base) progname = progname_from_file(log_file_name) logger.progname = progname + return logger if logger_class.nil? + create_wrapper_logger(progname, logger_class, logger) end diff --git a/spec/lib/vmdb/loggers_spec.rb b/spec/lib/vmdb/loggers_spec.rb index 53153d9ae28e..d12b6f033240 100644 --- a/spec/lib/vmdb/loggers_spec.rb +++ b/spec/lib/vmdb/loggers_spec.rb @@ -190,10 +190,6 @@ def in_container_env(example) context "in a container environment" do around { |example| in_container_env(example) } - it "has a container logger" do - expect(container_log).to_not be_nil - end - include_examples "has basic logging functionality" end end @@ -212,12 +208,10 @@ def in_container_env(example) it "will honor the log level in the container logger" do log = described_class.create_logger(log_file_name) - container_log = log.wrapped_logger described_class.apply_config_value({:level_foo => :error}, log, :level_foo) - expect(log.level).to eq(Logger::ERROR) - expect(container_log.level).to eq(Logger::ERROR) + expect(log.level).to eq(Logger::ERROR) end end end