Class: XMPPLogger
- Inherits:
-
Logger
- Object
- Logger
- XMPPLogger
- Defined in:
- lib/xmpp4log.rb
Instance Attribute Summary collapse
-
#jabber ⇒ Object
Returns the value of attribute jabber.
-
#mute ⇒ Object
Returns the value of attribute mute.
-
#rd ⇒ Object
Returns the value of attribute rd.
-
#thread ⇒ Object
Returns the value of attribute thread.
-
#users ⇒ Object
Returns the value of attribute users.
-
#wr ⇒ Object
Returns the value of attribute wr.
Instance Method Summary collapse
- #can_speak? ⇒ Boolean
- #deliver(msg) ⇒ Object
- #handle_commands ⇒ Object
-
#initialize(login, pass, users) ⇒ XMPPLogger
constructor
A new instance of XMPPLogger.
- #run ⇒ Object
Constructor Details
#initialize(login, pass, users) ⇒ XMPPLogger
Returns a new instance of XMPPLogger.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/xmpp4log.rb', line 33 def initialize(login, pass, users) @jabber = Jabber::Simple.new(login, pass) @users = users @mute = false @rd, @wr = IO.pipe super(@wr) @thread = Thread.new do run end end |
Instance Attribute Details
#jabber ⇒ Object
Returns the value of attribute jabber.
31 32 33 |
# File 'lib/xmpp4log.rb', line 31 def jabber @jabber end |
#mute ⇒ Object
Returns the value of attribute mute.
31 32 33 |
# File 'lib/xmpp4log.rb', line 31 def mute @mute end |
#rd ⇒ Object
Returns the value of attribute rd.
31 32 33 |
# File 'lib/xmpp4log.rb', line 31 def rd @rd end |
#thread ⇒ Object
Returns the value of attribute thread.
31 32 33 |
# File 'lib/xmpp4log.rb', line 31 def thread @thread end |
#users ⇒ Object
Returns the value of attribute users.
31 32 33 |
# File 'lib/xmpp4log.rb', line 31 def users @users end |
#wr ⇒ Object
Returns the value of attribute wr.
31 32 33 |
# File 'lib/xmpp4log.rb', line 31 def wr @wr end |
Instance Method Details
#can_speak? ⇒ Boolean
60 61 62 |
# File 'lib/xmpp4log.rb', line 60 def can_speak? not @mute end |
#deliver(msg) ⇒ Object
44 45 46 |
# File 'lib/xmpp4log.rb', line 44 def deliver(msg) @users.each {|user| @jabber.deliver(user, msg)} if can_speak? end |
#handle_commands ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/xmpp4log.rb', line 64 def handle_commands @jabber. do |msg| case msg.body.downcase when 'mute' self.mute = true self << "Logger set muted by #{msg.from}" when 'demute' self.mute = false self << "Logger set unmuted by #{msg.from}" when 'debug' self.level = Logger::DEBUG self << "Logger set to DEBUG level by #{msg.from}" when 'info' self.level = Logger::INFO self << "Logger set to INFO level by #{msg.from}" when 'warn' self.level = Logger::WARN self << "Logger set to WARN level by #{msg.from}" when 'error' self.level = Logger::ERROR self << "Logger set to ERROR level by #{msg.from}" when 'fatal' self.level = Logger::FATAL self << "Logger set to FATAL level by #{msg.from}" end end end |
#run ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xmpp4log.rb', line 48 def run loop do r,w,e = select([@rd], nil, nil, 1) if r != nil msg = r[0].read_nonblock(1024) break if msg.empty? #XXX nothing to read? deliver(msg) if msg and not msg.empty? end handle_commands end end |