Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Now can specify logger

  • Loading branch information...
commit 9602435a276dab2a68cc56e222f35b998e5960cc 1 parent 625b196
Ary Borenszweig asterite authored
Showing with 14 additions and 11 deletions.
  1. +11 −8 lib/msn/messenger.rb
  2. +3 −3 lib/msn/protocol.rb
19 lib/msn/messenger.rb
View
@@ -2,6 +2,17 @@ class Msn::Messenger
attr_reader :username
attr_reader :password
+ class << self
+ attr_accessor :logger
+
+ def log_info(message)
+ return unless logger
+
+ logger.info message
+ end
+ end
+
+
def initialize(username, password)
@username = username
@password = password
@@ -106,13 +117,5 @@ def call_handler(handler, *args)
Fiber.new { handler.call(*args) }.resume
end
end
-
- def self.debug
- @debug
- end
-
- def self.debug=(debug)
- @debug = debug
- end
end
6 lib/msn/protocol.rb
View
@@ -7,7 +7,7 @@ def post_init
end
def receive_line(line)
- puts "<< #{line}" if Msn::Messenger.debug
+ Msn::Messenger.log_info "<< #{line}"
pieces = line.split(' ')
@@ -47,7 +47,7 @@ def handle_payload_command(pieces)
end
def receive_binary_data(data)
- puts "<<* #{data}" if Msn::Messenger.debug
+ Msn::Messenger.log_info "<<* #{data}"
handle_event @header, data
end
@@ -91,7 +91,7 @@ def send_payload_command_and_wait(command, *args)
end
def send_command_internal(text)
- puts ">> #{text}" if Msn::Messenger.debug
+ Msn::Messenger.log_info ">> #{text}"
send_data text
@trid += 1
end
Please sign in to comment.
Something went wrong with that request. Please try again.