Class: Logfoo::App

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

Constant Summary collapse

@@appenders =
[IoAppender.new]
@@exception_handlers =
[StderrExceptionHanlder.new]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



9
10
11
12
# File 'lib/logfoo/app.rb', line 9

def initialize
  @queue = Queue.new
  @lock  = Mutex.new
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

.appenders(*fn) ⇒ Object



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

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

.exception_handlers(*fn) ⇒ Object



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

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

.handle_exception(ex, scope = nil, context = {}) ⇒ Object



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

def handle_exception(ex, scope = nil, context = {})
  @@exception_handlers.each{|fn| fn.call(ex, scope, context) }
end

.reset!Object



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

def reset!
  @@appenders          = [IoAppender.new]
  @@exception_handlers = [StderrExceptionHanlder.new]
end

Instance Method Details

#append(entry) ⇒ Object



35
36
37
# File 'lib/logfoo/app.rb', line 35

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

#startObject



14
15
16
17
18
19
20
# File 'lib/logfoo/app.rb', line 14

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

#started?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/logfoo/app.rb', line 22

def started?
  !!@thread
end

#stopObject



26
27
28
29
30
31
32
33
# File 'lib/logfoo/app.rb', line 26

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