Use rails logger
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Râu Cao 2024-10-18 18:21:24 +02:00
parent 79ef9fa6d5
commit 21c6264ea9
Signed by: raucao
GPG Key ID: 37036C356E56CC51
3 changed files with 10 additions and 10 deletions

View File

@ -28,7 +28,7 @@ module NostrManager
client.on :message do |m|
msg = JSON.parse(m) rescue nil
if msg && msg[0] == "EVENT" && msg[2]
puts "#{log_prefix} Event received: #{msg[2]["id"]}"
Rails.logger.debug "#{log_prefix} Event received: #{msg[2]["id"]}"
mutex.synchronize do
event = msg[2]
received_event.signal
@ -48,7 +48,7 @@ module NostrManager
end
end
rescue Timeout::Error
puts "#{log_prefix} Timeout: No event received within #{TIMEOUT} seconds"
Rails.logger.debug "#{log_prefix} Timeout: No event received within #{TIMEOUT} seconds"
ensure
thread.exit
end

View File

@ -20,7 +20,7 @@ module NostrManager
end
if received_events >= @max_events
puts "Found #{@max_events} events, ending the search"
Rails.logger.debug "Found #{@max_events} events, ending the search"
break
end
end

View File

@ -19,28 +19,28 @@ module NostrManager
thread = Thread.new do
client.on :connect do
puts "#{log_prefix} Publishing #{event.id}..."
Rails.logger.debug "#{log_prefix} Publishing #{event.id}..."
client.publish event
end
client.on :error do |e|
puts "#{log_prefix} Error: #{e}"
puts "#{log_prefix} Closing thread..."
Rails.logger.debug "#{log_prefix} Error: #{e}"
Rails.logger.debug "#{log_prefix} Closing thread..."
thread.exit
end
client.on :message do |m|
puts "#{log_prefix} Message: #{m}"
Rails.logger.debug "#{log_prefix} Message: #{m}"
msg = JSON.parse(m) rescue []
if msg[0] == "OK" && msg[1] == event.id && msg[2]
puts "#{log_prefix} Event published. Closing thread..."
Rails.logger.debug "#{log_prefix} Event published. Closing thread..."
else
puts "#{log_prefix} Unexpected message from relay. Closing thread..."
Rails.logger.debug "#{log_prefix} Unexpected message from relay. Closing thread..."
end
thread.exit
end
puts "#{log_prefix} Connecting to #{relay.url}..."
Rails.logger.debug "#{log_prefix} Connecting to #{relay.url}..."
client.connect relay
end