Class: Logfoo::App

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/logfoo/app.rb,
lib/logfoo/app.rb

Constant Summary collapse

IGNORE_ME_ERROR =
RuntimeError.new("ignore me")
@@appenders =
[]
@@exception_handlers =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



11
12
13
14
15
16
# File 'lib/logfoo/app.rb', line 11

def initialize
  @queue = Queue.new
  @lock  = Mutex.new

  start
end

Class Method Details

._append(entry) ⇒ Object



82
83
84
# File 'lib/logfoo/app.rb', line 82

def _append(entry)
  @@appenders.each{|fn| fn.call(entry) }
end

._handle_exception(entry) ⇒ Object



78
79
80
# File 'lib/logfoo/app.rb', line 78

def _handle_exception(entry)
  @@exception_handlers.each{|fn| fn.call(entry) }
end

._reset!Object



86
87
88
89
# File 'lib/logfoo/app.rb', line 86

def _reset!
  appenders IoAppender.new
  exception_handlers StderrExceptionHanlder.new
end

.appenders(*fn) ⇒ Object



70
71
72
# File 'lib/logfoo/app.rb', line 70

def appenders(*fn)
  @@appenders = fn.flatten
end

.exception_handlers(*fn) ⇒ Object



74
75
76
# File 'lib/logfoo/app.rb', line 74

def exception_handlers(*fn)
  @@exception_handlers = fn.flatten
end

Instance Method Details

#append(entry) ⇒ Object



39
40
41
# File 'lib/logfoo/app.rb', line 39

def append(entry)
  @queue.push(entry) if @thread
end

#startObject



18
19
20
21
22
23
24
# File 'lib/logfoo/app.rb', line 18

def start
  @lock.synchronize do
    unless @thread
      @thread = main_loop
    end
  end
end

#started?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/logfoo/app.rb', line 26

def started?
  !!@thread
end

#stopObject



30
31
32
33
34
35
36
37
# File 'lib/logfoo/app.rb', line 30

def stop
  @lock.synchronize do
    return unless @thread
    append(:shutdown)
    @thread.join
    @thread = nil
  end
end