Class: Logfoo::App
- Inherits:
-
Object
- Object
- Logfoo::App
- Includes:
- Singleton
- Defined in:
- lib/logfoo/app.rb,
lib/logfoo/app.rb
Constant Summary collapse
- IGNORE_ME_ERROR =
RuntimeError.new("ignore me")
- @@appenders =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #append(line) ⇒ 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.
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
74 75 76 |
# File 'lib/logfoo/app.rb', line 74 def _append(entry) @@appenders.each{|fn| fn.call(entry) } end |
._reset! ⇒ Object
78 79 80 |
# File 'lib/logfoo/app.rb', line 78 def _reset! appenders IoAppender.new end |
.appenders(*fn) ⇒ Object
70 71 72 |
# File 'lib/logfoo/app.rb', line 70 def appenders(*fn) @@appenders = fn.flatten end |
Instance Method Details
#append(line) ⇒ Object
40 41 42 |
# File 'lib/logfoo/app.rb', line 40 def append(line) @queue.push(line) if @thread end |
#start ⇒ Object
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
27 28 29 |
# File 'lib/logfoo/app.rb', line 27 def started? !!@thread end |
#stop ⇒ Object
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 |