Sha256: 3662956eb54e5b1c240745614f06dd90ee4150de52ba8ced10d093ce1f3cf5cf

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

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

require 'logger'

module Jabber
  def Jabber::logger
    @@logger ||= Logger.new($stderr)
  end
  
  # Set the logger to use for debug and warn (if enabled)
  def Jabber::logger=(logger)
    @@logger = logger
  end

  # Is debugging mode enabled ?
  @@debug = false

  # Is warnings mode enabled ?
  @@warnings = 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.')
      #if debug is enabled, we should automatically enable warnings too
      Jabber::warnings = true
    end
  end

  # Enable/disable warnings mode.
  def Jabber::warnings=(warnings)
    @@warnings = warnings
    if @@warnings
      warnlog('Warnings 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 beginning of each line but the
  # first one. Time is prepended to the string.
  def Jabber::debuglog(string)
    return if not @@debug
    logger.debug string.chomp.gsub("\n", "\n    ")
  end
  
  # Outputs a string only if warnings mode is enabled.
  def Jabber::warnlog(string)
    return if not @@warnings
    logger.warn string.chomp.gsub("\n", "\n    ")
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xmpp4r-0.5.6 lib/xmpp4r/debuglog.rb