Class: Logfoo::App
- Inherits:
-
Object
- Object
- Logfoo::App
- 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
- .append(entry) ⇒ Object
- .appenders(*fn) ⇒ Object
- .exception_handlers(*fn) ⇒ Object
- .handle_exception(ex, scope = nil, context = {}) ⇒ Object
- .reset! ⇒ Object
Instance Method Summary collapse
- #append(entry) ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize ⇒ App
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 |
#start ⇒ Object
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
22 23 24 |
# File 'lib/logfoo/app.rb', line 22 def started? !!@thread end |
#stop ⇒ Object
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 |