Class: Wildcloud::Logger::Middleware::File

Inherits:
Object
  • Object
show all
Defined in:
lib/wildcloud/logger/middleware/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ File

Returns a new instance of File.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wildcloud/logger/middleware/file.rb', line 22

def initialize(app, options = {})
  @options = options
  @options[:io].sync = true
  @queue = Queue.new
  @app = app
  @thread = Thread.new do
    loop do
      begin
        msg = @queue.pop
        if @options[:key]
          log = msg[@options[:key]]
        else
          log = msg[:level].to_s
          log << " (#{Time.at(msg[:timestamp])})"
          log << " :"
          log << " #{msg[:application]}" if msg[:application]
          log << " :"
          log << " #{msg[:component]}" if msg[:component]
          log << " :"
          log << " #{msg[:message]}"
        end
        @options[:io].puts(log)
      rescue Exception => e
        puts e.message
      end
    end
  end
end

Instance Method Details

#call(msg) ⇒ Object



51
52
53
54
# File 'lib/wildcloud/logger/middleware/file.rb', line 51

def call(msg)
  @queue << msg
  @app.call(msg)
end