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
17
# File 'lib/logfoo/app.rb', line 11

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

  start
end

Class Method Details

._append(entry) ⇒ Object



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

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

._handle_exception(entry) ⇒ Object



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

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

._reset!Object



89
90
91
92
# File 'lib/logfoo/app.rb', line 89

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

.appenders(*fn) ⇒ Object



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

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

.exception_handlers(*fn) ⇒ Object



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

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

Instance Method Details

#append(entry) ⇒ Object



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

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

#startObject



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

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

#started?Boolean

Returns:

  • (Boolean)


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

def started?
  !!@thread
end

#stopObject



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

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