Class: Streamforce::Extension::Logging
- Inherits:
-
Object
- Object
- Streamforce::Extension::Logging
- Defined in:
- lib/streamforce/extension/logging.rb
Instance Method Summary collapse
- #debug(message, text) ⇒ Object
- #error(message, text) ⇒ Object
- #incoming(payload, callback) ⇒ Object
- #info(message, text) ⇒ Object
-
#initialize(logger) ⇒ Logging
constructor
A new instance of Logging.
- #log_incoming_connect(message) ⇒ Object
- #log_incoming_handshake(message) ⇒ Object
- #log_incoming_subscribe(message) ⇒ Object
- #log_outgoing_subscribe(message) ⇒ Object
- #outgoing(payload, callback) ⇒ Object
- #warn(message, text) ⇒ Object
Constructor Details
#initialize(logger) ⇒ Logging
Returns a new instance of Logging.
2 3 4 |
# File 'lib/streamforce/extension/logging.rb', line 2 def initialize(logger) @logger = logger end |
Instance Method Details
#debug(message, text) ⇒ Object
78 79 80 |
# File 'lib/streamforce/extension/logging.rb', line 78 def debug(, text) @logger.debug "[#{.client_id}##{.id}] #{text}" end |
#error(message, text) ⇒ Object
90 91 92 |
# File 'lib/streamforce/extension/logging.rb', line 90 def error(, text) @logger.error "[#{.client_id}##{.id}] #{text}" end |
#incoming(payload, callback) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/streamforce/extension/logging.rb', line 6 def incoming(payload, callback) = Streamforce::Message.new(payload) case .channel when "/meta/handshake" log_incoming_handshake() when "/meta/connect" log_incoming_connect() when "/meta/subscribe" log_incoming_subscribe() else @logger.debug "[#{.channel}] #{.data}" end callback.call(payload) end |
#info(message, text) ⇒ Object
82 83 84 |
# File 'lib/streamforce/extension/logging.rb', line 82 def info(, text) @logger.info "[#{.client_id}##{.id}] #{text}" end |
#log_incoming_connect(message) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/streamforce/extension/logging.rb', line 48 def log_incoming_connect() if .success? debug , "Connection successful!" else error , "Connection failed: #{.}" end end |
#log_incoming_handshake(message) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/streamforce/extension/logging.rb', line 40 def log_incoming_handshake() if .success? @logger.debug "[Server] Handshake accepted, assigning client_id=#{.client_id}" else @logger.error "[Server] Connection was refused: #{.}" end end |
#log_incoming_subscribe(message) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/streamforce/extension/logging.rb', line 70 def log_incoming_subscribe() if .success? info , "Successfully subscribed to #{.subscription}" else error , "Subscription for #{.subscription} failed: #{.}" end end |
#log_outgoing_subscribe(message) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/streamforce/extension/logging.rb', line 56 def log_outgoing_subscribe() replay_id = .replay_id replay_info = if .no_replay? "for all new messages" elsif . "and requesting all stored messages" else "and requesting all messages newer than ##{replay_id}" end info , "Subscribing to #{.subscription} #{replay_info}" end |
#outgoing(payload, callback) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/streamforce/extension/logging.rb', line 23 def outgoing(payload, callback) = Streamforce::Message.new(payload) case .channel when "/meta/handshake" @logger.debug "[Client] Handshake requested..." when "/meta/connect" debug , "Sending connection request" when "/meta/subscribe" log_outgoing_subscribe() else @logger.debug "[#{.channel}] #{.data}" end callback.call(payload) end |
#warn(message, text) ⇒ Object
86 87 88 |
# File 'lib/streamforce/extension/logging.rb', line 86 def warn(, text) @logger.warn "[#{.client_id}##{.id}] #{text}" end |