Class: Nostr::Client::Logger

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

Overview

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

Direct Known Subclasses

ColorLogger, PlainLogger

Instance Method Summary collapse

Instance Method Details

#attach_to(client) ⇒ void

This method returns an undefined value.

Attaches event handlers to the specified Nostr client for logging purposes

Examples:

Attaching the logger to a client

client = Nostr::Client.new
logger = Nostr::Client::Logger.new
logger.attach_to(client)

# Now, actions like connecting, sending messages, receiving messages,
# errors, and closing the connection will be logged to the console.


23
24
25
26
27
28
29
30
31
# File 'lib/nostr/client/logger.rb', line 23

def attach_to(client)
  logger_instance = self

  client.on(:connect) { |relay| logger_instance.on_connect(relay) }
  client.on(:message) { |message| logger_instance.on_message(message) }
  client.on(:send) { |message| logger_instance.on_send(message) }
  client.on(:error) { |message| logger_instance.on_error(message) }
  client.on(:close) { |code, reason| logger_instance.on_close(code, reason) }
end

#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



82
# File 'lib/nostr/client/logger.rb', line 82

def on_close(code, reason); 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



41
# File 'lib/nostr/client/logger.rb', line 41

def on_connect(relay); 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



71
# File 'lib/nostr/client/logger.rb', line 71

def on_error(message); 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



51
# File 'lib/nostr/client/logger.rb', line 51

def on_message(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



61
# File 'lib/nostr/client/logger.rb', line 61

def on_send(message); end