lib/logjam_agent/request.rb in logjam_agent-0.4.4 vs lib/logjam_agent/request.rb in logjam_agent-0.4.5

- old
+ new

@@ -10,10 +10,11 @@ @env = env @forwarder = Forwarders.get(app, env) @lines = [] @id = UUID4R::uuid(1).gsub('-','') @fields = initial_fields.merge(:request_id => @id, :host => LogjamAgent.hostname, :process_id => Process.pid, :lines => @lines) + @mutex = Mutex.new end def id "#{@app}-#{@env}-#{@id}" end @@ -21,14 +22,18 @@ def caller_id @fields[:caller_id] end def add_line(severity, timestamp, message) - @lines << [severity, format_time(timestamp), message.strip] + @mutex.synchronize do + @lines << [severity, format_time(timestamp), message.strip] + end end def add_exception(exception) - ((@fields[:exceptions] ||= []) << exception).uniq! + @mutex.synchronize do + ((@fields[:exceptions] ||= []) << exception).uniq! + end end def forward engine = @fields.delete(:engine) @forwarder.forward(@fields.to_json, engine)