Skip to content

Commit

Permalink
Optimize trace and debug logging (#343)
Browse files Browse the repository at this point in the history
I missed a few in the previous PR

Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored Sep 26, 2024
1 parent e8cfc31 commit 430086f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/openhab/core/items/generic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/openhab/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
10 changes: 6 additions & 4 deletions lib/openhab/dsl/items/timed_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/openhab/dsl/rules/triggers/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/openhab/dsl/thread_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion lib/openhab/osgi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 430086f

Please sign in to comment.