Skip to content

Commit

Permalink
Add a log_path_from_file helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Nov 28, 2023
1 parent 9f8ddcd commit 6ed92ad
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/vmdb/loggers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ def self.create_logger(log_file_name, logger_class = ManageIQ::Loggers::Base)

private_class_method def self.create_file_logger(log_file, logger_class)
log_file = log_path_from_file(log_file)
progname = log_file.try(:basename, ".*").to_s
progname = progname_from_file(log_file)

logger_class.new(log_file, :progname => progname)
end

private_class_method def self.create_container_logger(log_file_name, logger_class)
return nil unless (logger = create_raw_container_logger)

create_wrapper_logger(log_file_name, logger_class, logger)
progname = progname_from_file(log_file_name)
create_wrapper_logger(progname, logger_class, logger)
end

private_class_method def self.create_raw_container_logger
Expand All @@ -69,7 +70,8 @@ def self.create_logger(log_file_name, logger_class = ManageIQ::Loggers::Base)
private_class_method def self.create_journald_logger(log_file_name, logger_class)
return nil unless (logger = create_raw_journald_logger)

create_wrapper_logger(log_file_name, logger_class, logger)
progname = progname_from_file(log_file_name)
create_wrapper_logger(progname, logger_class, logger)
end

private_class_method def self.create_raw_journald_logger
Expand All @@ -86,13 +88,11 @@ def self.create_logger(log_file_name, logger_class = ManageIQ::Loggers::Base)
end

private_class_method def self.progname_from_file(log_file_name)
File.basename(log_file_name, ".*")
log_file = Pathname.new(log_file) if log_file.kind_of?(String)
log_file.try(:basename, ".*").to_s
end

private_class_method def self.create_wrapper_logger(log_file, logger_class, wrapped_logger)
log_file = log_path_from_file(log_file)
progname = log_file.try(:basename, ".*").to_s

private_class_method def self.create_wrapper_logger(progname, logger_class, wrapped_logger)
logger_class.new(nil, :progname => progname).tap do |logger|
# HACK: In order to access the wrapped logger in test, we inject it as an instance var.
if Rails.env.test?
Expand Down

0 comments on commit 6ed92ad

Please sign in to comment.