Class: Nostr::Client::ColorLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/nostr/client/color_logger.rb

Overview

Logs connection events, messages sent and received, errors, and connection closures in color.

Instance Method Summary collapse

Methods inherited from Logger

#attach_to

Instance Method Details

#on_close(code, reason) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Logs a closure of connection with a relay



64
65
66
# File 'lib/nostr/client/color_logger.rb', line 64

def on_close(code, reason)
  puts "\u001b[31m\u001b[1mConnection closed: \u001b[22m#{reason} (##{code})\u001b[0m"
end

#on_connect(relay) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Logs connection to a relay



15
16
17
# File 'lib/nostr/client/color_logger.rb', line 15

def on_connect(relay)
  puts "\u001b[32m\u001b[1mConnected to the relay\u001b[22m #{relay.name} (#{relay.url})\u001b[0m"
end

#on_error(message) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Logs an error message



51
52
53
# File 'lib/nostr/client/color_logger.rb', line 51

def on_error(message)
  puts "\u001b[31m\u001b[1mError: \u001b[22m#{message}\u001b[0m"
end

#on_message(message) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Logs a message received from the relay



27
28
29
# File 'lib/nostr/client/color_logger.rb', line 27

def on_message(message)
  puts "\u001b[32m\u001b[1m◄-\u001b[0m #{message}"
end

#on_send(message) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Logs a message sent to the relay



39
40
41
# File 'lib/nostr/client/color_logger.rb', line 39

def on_send(message)
  puts "\u001b[32m\u001b[1m-►\u001b[0m #{message}"
end