class Urbivore::Logger

Constants

DEFAULT_BATCH_SIZE
DEFAULT_SLEEP_TIME

worker constants default to 250ms sleep (more? less?)

DEFAULT_TOTAL_WORKERS

Attributes

configured_level[R]
configured_levels[R]

Public Class Methods

batch_size() click to toggle source
# File lib/urbivore/logger.rb, line 55
def batch_size
  @batch_size || DEFAULT_BATCH_SIZE
end
batch_size=(batch_size) click to toggle source
# File lib/urbivore/logger.rb, line 76
def batch_size=(batch_size)
  unless batch_size.is_a?(Fixnum) || !batch_size
    raise Urbivore::Exceptions::ConfigurationError.new("Log.batch_size must be a number")
  end
  @batch_size = batch_size
end
logger() click to toggle source
# File lib/urbivore/logger.rb, line 35
def logger
  self
end
process(entry) click to toggle source
# File lib/urbivore/logger.rb, line 20
def process(entry)
  processor.process(entry)
end
processor(processor = nil) click to toggle source
# File lib/urbivore/logger.rb, line 24
def processor(processor = nil)
  if processor
    unless processor.respond_to?(:process)
      raise Urbivore::Exceptions::ConfigurationError.new("Processor must respond_to?(:process)")
    end
    @processor = processor
  else
    @processor ||= Urbs::BasicProcessor
  end
end
queue() click to toggle source
# File lib/urbivore/logger.rb, line 43
def queue
  @queue ||= Queue.new
end
restart_logging(halt = false) click to toggle source

THREAD SAFETY…

# File lib/urbivore/logger.rb, line 84
def restart_logging(halt = false)
  Thread.exclusive do
    reset_state
    if halt
      true
    else
      @keep_going   = true
      total_workers.times do
        workers << Thread.new do
          while @keep_going
            sleep sleep_time
            entries   = []
            batch_size.times do 
              entries << queue.pop
            end
            entries.each { |entry| process(entry) }
          end
        end
      end
    end
  end
end
sleep_time() click to toggle source
# File lib/urbivore/logger.rb, line 47
def sleep_time
  @sleep_time || DEFAULT_SLEEP_TIME
end
sleep_time=(sleep_time) click to toggle source
# File lib/urbivore/logger.rb, line 59
def sleep_time=(sleep_time)
  unless sleep_time.is_a?(Numeric) || !sleep_time
    raise Urbivore::Exceptions::ConfigurationError.new("Log.sleep_time must be a number")
  end

  # we should figure out whether access to this instance var
  # should be locked, in this method and the getter...
  @sleep_time = sleep_time
end
submit(entry) click to toggle source

use this to enqueue entries

# File lib/urbivore/logger.rb, line 15
def submit(entry)
  # any prep work on the object goes here...
  queue.push(entry)
end
total_workers() click to toggle source
# File lib/urbivore/logger.rb, line 51
def total_workers
  @total_workers || DEFAULT_TOTAL_WORKERS
end
total_workers=(total_workers) click to toggle source
# File lib/urbivore/logger.rb, line 69
def total_workers=(total_workers)
  unless total_workers.is_a?(Fixnum) || !total_workers
    raise Urbivore::Exceptions::ConfigurationError.new("Log.total_workers must be a number")
  end
  @total_workers = total_workers
end
workers() click to toggle source
# File lib/urbivore/logger.rb, line 39
def workers
  @workers ||= []
end

Private Class Methods

reset_state() click to toggle source
# File lib/urbivore/logger.rb, line 109
def reset_state
  @keep_going   = false
  workers.each { |thr| thr.join }
  @workers      = nil
  @logging      = false
  # close file handles, network connections and the like
  # note we leave queue alone, so it can keep getting entries
  # while we're reloading
  # processor.reset_state
end