Class: Wildcloud::Logger::Middleware::File
- Inherits:
-
Object
- Object
- Wildcloud::Logger::Middleware::File
- Defined in:
- lib/wildcloud/logger/middleware/file.rb
Instance Method Summary collapse
- #call(msg) ⇒ Object
-
#initialize(app, options = {}) ⇒ File
constructor
A new instance of File.
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[: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. 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 |