Skip to content

Commit

Permalink
Fix logger error when no toplevel file is found (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng authored Nov 8, 2024
1 parent f610bd2 commit ff18943
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/openhab/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def logger(object)
# @!visibility private
def top_level_file
caller_locations.find { |caller| caller.base_label == "<main>" }
.then { |caller| cleanup_path(caller.path) }
&.then { |caller| cleanup_path(caller.path) }
end

private
Expand Down Expand Up @@ -376,9 +376,10 @@ def current_logger
return @file_logger unless (rule_uid = Thread.current[:openhab_rule_uid])

rule_type = Thread.current[:openhab_rule_type]
top_level_file = Log.top_level_file&.then { |file| "#{file}." }
full_id = "#{rule_type}:#{rule_uid}"

self.class.rule_loggers[full_id] ||= Logger.new("#{Logger::PREFIX}.#{Log.top_level_file}.#{rule_type}.#{rule_uid
self.class.rule_loggers[full_id] ||= Logger.new("#{Logger::PREFIX}.#{top_level_file}#{rule_type}.#{rule_uid
.gsub(/[^A-Za-z0-9_.:-]/, "")}")
end

Expand Down

0 comments on commit ff18943

Please sign in to comment.