Class: Thrifty::Logger::App

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/thrifty/logger/app.rb,
lib/thrifty/logger/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
13
14
# File 'lib/thrifty/logger/app.rb', line 9

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

  Thrifty::Signals.register(method(:stop))
end

Class Method Details

.append(entry) ⇒ Object



75
76
77
# File 'lib/thrifty/logger/app.rb', line 75

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

.appenders(*fn) ⇒ Object



67
68
69
# File 'lib/thrifty/logger/app.rb', line 67

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

.exception_handlers(*fn) ⇒ Object



71
72
73
# File 'lib/thrifty/logger/app.rb', line 71

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

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



79
80
81
# File 'lib/thrifty/logger/app.rb', line 79

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

.reset!Object



83
84
85
86
# File 'lib/thrifty/logger/app.rb', line 83

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

Instance Method Details

#append(entry) ⇒ Object



37
38
39
# File 'lib/thrifty/logger/app.rb', line 37

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

#startObject



16
17
18
19
20
21
22
# File 'lib/thrifty/logger/app.rb', line 16

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

#started?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/thrifty/logger/app.rb', line 24

def started?
  !!@thread
end

#stopObject



28
29
30
31
32
33
34
35
# File 'lib/thrifty/logger/app.rb', line 28

def stop
  @lock.synchronize do
    return unless @thread
    @queue.push :shutdown
    @thread.join
    @thread = nil
  end
end