class Logfoo::App

Constants

IGNORE_ME_ERROR

Public Class Methods

_append(entry) click to toggle source
# File lib/logfoo/app.rb, line 74
def _append(entry)
  @@appenders.each{|fn| fn.call(entry) }
end
_reset!() click to toggle source
# File lib/logfoo/app.rb, line 78
def _reset!
  appenders IoAppender.new
end
appenders(*fn) click to toggle source
# File lib/logfoo/app.rb, line 70
def appenders(*fn)
  @@appenders = fn.flatten
end
new() click to toggle source
# File lib/logfoo/app.rb, line 11
def initialize
  @queue  = Queue.new
  @lock   = Mutex.new
  @thread = nil

  start
end

Public Instance Methods

append(line) click to toggle source
# File lib/logfoo/app.rb, line 40
def append(line)
  @queue.push(line) if @thread
end
start() click to toggle source
# File lib/logfoo/app.rb, line 19
def start
  @lock.synchronize do
    unless @thread
      @thread = main_loop
    end
  end
end
started?() click to toggle source
# File lib/logfoo/app.rb, line 27
def started?
  !!@thread
end
stop() click to toggle source
# File lib/logfoo/app.rb, line 31
def stop
  @lock.synchronize do
    return unless @thread
    append(:shutdown)
    @thread.join
    @thread = nil
  end
end

Private Instance Methods

main_loop() click to toggle source
# File lib/logfoo/app.rb, line 46
def main_loop ; Thread.new do
  begin
    loop do
      line = @queue.pop
      case line
      when :shutdown
        break
      when :boom
        raise IGNORE_ME_ERROR
      else
        App._append(line)
      end
    end
  rescue Exception => ex
    line = ErrLine.build(logger_name: self.class, exception: ex)
    App._append(line)
    retry
  end
end ; end