Skip to content

Commit

Permalink
Return the raw logger unless logger_class is present
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Nov 28, 2023
1 parent b8aabc6 commit 872369b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lib/vmdb/loggers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
8 changes: 1 addition & 7 deletions spec/lib/vmdb/loggers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 872369b

Please sign in to comment.