From 430086f8c9e0ff69495a1b35f66b913553c6b866 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Fri, 27 Sep 2024 00:18:30 +1000 Subject: [PATCH] Optimize trace and debug logging (#343) I missed a few in the previous PR Signed-off-by: Jimmy Tanagra --- lib/openhab/core/items/generic_item.rb | 4 ++-- lib/openhab/dsl.rb | 2 +- lib/openhab/dsl/items/timed_command.rb | 10 ++++++---- lib/openhab/dsl/rules/triggers/channel.rb | 4 ++-- lib/openhab/dsl/thread_local.rb | 2 +- lib/openhab/osgi.rb | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/openhab/core/items/generic_item.rb b/lib/openhab/core/items/generic_item.rb index 2b11f9d051..520df4fdb5 100644 --- a/lib/openhab/core/items/generic_item.rb +++ b/lib/openhab/core/items/generic_item.rb @@ -158,7 +158,7 @@ def state # def command(command) command = format_command(command) - logger.trace "Sending Command #{command} to #{name}" + logger.trace { "Sending Command #{command} to #{name}" } $events.send_command(self, command) Proxy.new(self) end @@ -201,7 +201,7 @@ def <<(command) # def update(state) state = format_update(state) - logger.trace "Sending Update #{state} to #{name}" + logger.trace { "Sending Update #{state} to #{name}" } $events.post_update(self, state) Proxy.new(self) end diff --git a/lib/openhab/dsl.rb b/lib/openhab/dsl.rb index 8881b691e7..e81b4aa881 100644 --- a/lib/openhab/dsl.rb +++ b/lib/openhab/dsl.rb @@ -1087,4 +1087,4 @@ def respond_to_missing?(method, include_private = false) Object.extend(OpenHAB::CoreExt::Ruby::Object::ClassMethods) OpenHAB::CoreExt::Ruby::Object.instance_variable_set(:@top_self, self) -logger.debug "openHAB JRuby Scripting Library Version #{OpenHAB::DSL::VERSION} Loaded" +logger.debug { "openHAB JRuby Scripting Library Version #{OpenHAB::DSL::VERSION} Loaded" } diff --git a/lib/openhab/dsl/items/timed_command.rb b/lib/openhab/dsl/items/timed_command.rb index 2d10cf9a02..4c034e569c 100644 --- a/lib/openhab/dsl/items/timed_command.rb +++ b/lib/openhab/dsl/items/timed_command.rb @@ -180,7 +180,7 @@ def command(command, for: nil, on_expire: nil, only_when_ensured: false, &block) create_ensured_timed_command.call else # timed command still pending; reset it - logger.trace "Outstanding Timed Command #{timed_command_details} encountered - rescheduling" + logger.trace { "Outstanding Timed Command #{timed_command_details} encountered - rescheduling" } timed_command_details.on_expire = on_expire unless on_expire.nil? timed_command_details.timer.reschedule(duration) # disable the cancel rule while we send the new command @@ -209,7 +209,7 @@ def create_timed_command(command, duration:, on_expire:) unmanaged_rule = Core.automation_manager.add_unmanaged_rule(cancel_rule) timed_command_details.rule_uid = unmanaged_rule.uid Core::Rules::Provider.current.add(unmanaged_rule) - logger.trace "Created Timed Command #{timed_command_details}" + logger.trace { "Created Timed Command #{timed_command_details}" } timed_command_details end @@ -219,12 +219,14 @@ def create_timed_command(command, duration:, on_expire:) def timed_command_timer(timed_command_details, duration) DSL.after(duration) do timed_command_details.mutex.synchronize do - logger.trace "Timed command expired - #{timed_command_details}" + logger.trace { "Timed command expired - #{timed_command_details}" } DSL.rules[timed_command_details.rule_uid].disable timed_command_details.resolution = :expired case timed_command_details.on_expire when Proc - logger.trace "Invoking block #{timed_command_details.on_expire} after timed command for #{name} expired" + logger.trace do + "Invoking block #{timed_command_details.on_expire} after timed command for #{name} expired" + end timed_command_details.on_expire.call(timed_command_details) when Core::Types::UnDefType update(timed_command_details.on_expire) diff --git a/lib/openhab/dsl/rules/triggers/channel.rb b/lib/openhab/dsl/rules/triggers/channel.rb index 40d1732191..7f3d65e33a 100644 --- a/lib/openhab/dsl/rules/triggers/channel.rb +++ b/lib/openhab/dsl/rules/triggers/channel.rb @@ -20,7 +20,7 @@ class Channel < Trigger # @param [Object] thing to combine with channels and iterate over # @return [Enumerable] enumerable channel ids to trigger on def self.channels(channels:, thing:) - logger.trace "Creating Channel/Thing Pairs for channels #{channels.inspect} and things #{thing.inspect}" + logger.trace { "Creating Channel/Thing Pairs for channels #{channels.inspect} and things #{thing.inspect}" } channels.flatten.product([thing].flatten) .map { |channel_thing| channel_id(*channel_thing) } end @@ -47,7 +47,7 @@ def self.channel_id(channel, thing) def trigger(channel:, trigger:, attach:) config = { "channelUID" => channel } config["event"] = trigger.to_s unless trigger.nil? - logger.trace "Creating Channel Trigger for channels #{channel.inspect} and config #{config.inspect}" + logger.trace { "Creating Channel Trigger for channels #{channel.inspect} and config #{config.inspect}" } append_trigger(type: CHANNEL_EVENT, config: config, attach: attach) end end diff --git a/lib/openhab/dsl/thread_local.rb b/lib/openhab/dsl/thread_local.rb index 24bf1037d8..54754662fe 100644 --- a/lib/openhab/dsl/thread_local.rb +++ b/lib/openhab/dsl/thread_local.rb @@ -41,7 +41,7 @@ def persist def thread_local(**values) old_values = values.to_h { |key, _value| [key, Thread.current[key]] } values.each { |key, value| Thread.current[key] = value } - logger.trace "Executing block with thread local context: #{values} - old context: #{old_values}" + logger.trace { "Executing block with thread local context: #{values} - old context: #{old_values}" } yield ensure old_values.each { |key, value| Thread.current[key] = value } diff --git a/lib/openhab/osgi.rb b/lib/openhab/osgi.rb index b68b9d0aa5..ee678f4902 100644 --- a/lib/openhab/osgi.rb +++ b/lib/openhab/osgi.rb @@ -24,7 +24,7 @@ def service(name, filter: nil) # def services(name, filter: nil) (bundle_context.get_service_references(name, filter) || []).map do |reference| - logger.trace "OSGi service found for '#{name}' using OSGi Service Reference #{reference}" + logger.trace { "OSGi service found for '#{name}' using OSGi Service Reference #{reference}" } bundle_context.get_service(reference) end end