Add plain text and coloured logging to the Client

Logs websocket events (connect, message, error and close events)
This commit is contained in:
Wilson Silva
2024-04-13 13:55:36 +01:00
parent a0cf41bfb4
commit 90ab1a6149
19 changed files with 742 additions and 10 deletions

View File

@@ -18,11 +18,19 @@ module Nostr
# @api public
#
# @example Instantiating a client that logs all the events it sends and receives
# client = Nostr::Client.new(debug: true)
# client = Nostr::Client.new
#
def initialize
# @example Instantiating a client with no logging
# client = Nostr::Client.new(logger: nil)
#
# @example Instantiating a client with your own logger
# client = Nostr::Client.new(logger: YourLogger.new)
#
def initialize(logger: ColorLogger.new)
@subscriptions = {}
@logger = logger
logger&.attach_to(self)
initialize_channels
end
@@ -122,6 +130,14 @@ module Nostr
private
# The logger that prints all the events that the client sends and receives
#
# @api private
#
# @return [ClientLogger]
#
attr_reader :logger
# The subscriptions that the client has created
#
# @api private