Class: LogjamAgent::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/logjam_agent/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env, initial_fields) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
17
18
19
20
# File 'lib/logjam_agent/request.rb', line 11

def initialize(app, env, initial_fields)
  @app = app
  @env = env
  @forwarder = Forwarders.get(app, env)
  @lines = []
  @uuid = LogjamAgent.generate_uuid
  @fields = initial_fields.merge(:request_id => @uuid, :host => LogjamAgent.hostname, :process_id => Process.pid, :lines => @lines)
  @mutex = Mutex.new
  @ignored = false
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



9
10
11
# File 'lib/logjam_agent/request.rb', line 9

def fields
  @fields
end

#uuidObject (readonly)

Returns the value of attribute uuid.



9
10
11
# File 'lib/logjam_agent/request.rb', line 9

def uuid
  @uuid
end

Instance Method Details

#actionObject



34
35
36
# File 'lib/logjam_agent/request.rb', line 34

def action
  @fields[:action]
end

#add_exception(exception) ⇒ Object



52
53
54
55
56
# File 'lib/logjam_agent/request.rb', line 52

def add_exception(exception)
  @mutex.synchronize do
    ((@fields[:exceptions] ||= []) << exception).uniq!
  end
end

#add_line(severity, timestamp, message) ⇒ Object



46
47
48
49
50
# File 'lib/logjam_agent/request.rb', line 46

def add_line(severity, timestamp, message)
  @mutex.synchronize do
    @lines << [severity, format_time(timestamp), message.strip]
  end
end

#caller_actionObject



42
43
44
# File 'lib/logjam_agent/request.rb', line 42

def caller_action
  @fields[:caller_action]
end

#caller_idObject



38
39
40
# File 'lib/logjam_agent/request.rb', line 38

def caller_id
  @fields[:caller_id]
end

#forwardObject



58
59
60
61
62
63
64
65
# File 'lib/logjam_agent/request.rb', line 58

def forward
  return if @ignored
  engine = @fields.delete(:engine)
  # puts @fields.inspect
  @forwarder.forward(LogjamAgent.encode_payload(@fields), :engine => engine)
rescue Exception => e
  handle_forwarding_error(e)
end

#idObject



30
31
32
# File 'lib/logjam_agent/request.rb', line 30

def id
  "#{@app}-#{@env}-#{@uuid}"
end

#ignore!Object



22
23
24
# File 'lib/logjam_agent/request.rb', line 22

def ignore!
  @ignored = true
end

#ignored?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/logjam_agent/request.rb', line 26

def ignored?
  @ignored
end