Sha256: 9545769dce6d5e994fcea2717395894ed6e18bacba62f4e5b9530bf33eff699a

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://home.gna.org/xmpp4r/

module Jabber
  # Is debugging mode enabled ?
  @@debug = false

  # Enable/disable debugging mode. When debug mode is enabled, information
  # can be logged using Jabber::debuglog. When debug mode is disabled, calls
  # to Jabber::debuglog are just ignored.
  def Jabber::debug=(debug)
    @@debug = debug
    if @@debug
      debuglog('Debugging mode enabled.')
    end
  end

  # returns true if debugging mode is enabled. If you just want to log
  # something if debugging is enabled, use Jabber::debuglog instead.
  def Jabber::debug
    @@debug
  end
    
  # Outputs a string only if debugging mode is enabled. If the string includes
  # several lines, 4 spaces are added at the begginning of each line but the
  # first one. Time is prepended to the string.
  def Jabber::debuglog(string)
    return if not @@debug
    s = string.chomp.gsub("\n", "\n    ")
    t = Time::new.strftime('%H:%M:%S')
    puts "#{t} #{s}"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xmpp4r-0.3 lib/xmpp4r/debuglog.rb
xmpp4r-0.3.1 lib/xmpp4r/debuglog.rb
xmpp4r-0.3.2 lib/xmpp4r/debuglog.rb