Class: LogjamAgent::Request
- Inherits:
-
Object
- Object
- LogjamAgent::Request
- Defined in:
- lib/logjam_agent/request.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#log_device_ignored_lines ⇒ Object
Returns the value of attribute log_device_ignored_lines.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #action ⇒ Object
- #add_exception(exception, severity = Logger::ERROR) ⇒ Object
- #add_line(severity, timestamp, message) ⇒ Object
- #caller_action ⇒ Object
- #caller_id ⇒ Object
- #forward ⇒ Object
- #id ⇒ Object
- #ignore! ⇒ Object
- #ignored? ⇒ Boolean
-
#initialize(app, env, initial_fields) ⇒ Request
constructor
A new instance of Request.
- #trace_id ⇒ Object
Constructor Details
#initialize(app, env, initial_fields) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/logjam_agent/request.rb', line 12 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) @fields[:trace_id] ||= @uuid unless (revision = LogjamAgent.application_revision).blank? @fields[:revision] = revision end if ENV['CLUSTER'] @fields[:cluster] = ENV['CLUSTER'] end if ENV['DATACENTER'] @fields[:datacenter] = ENV['DATACENTER'] end if ENV['NAMESPACE'] @fields[:namespace] = ENV['NAMESPACE'] end if start_time = @fields.delete(:start_time) self.start_time = start_time end @mutex = Mutex.new @ignored = false @bytes_all_lines = 0 @max_bytes_all_lines = LogjamAgent.max_bytes_all_lines @max_line_length = LogjamAgent.max_line_length @lines_dropped = false end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
9 10 11 |
# File 'lib/logjam_agent/request.rb', line 9 def fields @fields end |
#log_device_ignored_lines ⇒ Object
Returns the value of attribute log_device_ignored_lines.
10 11 12 |
# File 'lib/logjam_agent/request.rb', line 10 def log_device_ignored_lines @log_device_ignored_lines end |
#start_time ⇒ Object
Returns the value of attribute start_time.
9 10 11 |
# File 'lib/logjam_agent/request.rb', line 9 def start_time @start_time end |
#uuid ⇒ Object (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
#action ⇒ Object
62 63 64 |
# File 'lib/logjam_agent/request.rb', line 62 def action @fields[:action] end |
#add_exception(exception, severity = Logger::ERROR) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/logjam_agent/request.rb', line 101 def add_exception(exception, severity = Logger::ERROR) @mutex.synchronize do if LogjamAgent.split_hard_and_soft_exceptions && severity < Logger::ERROR ((@fields[:soft_exceptions] ||= []) << exception).uniq! else ((@fields[:exceptions] ||= []) << exception).uniq! end end end |
#add_line(severity, timestamp, message) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/logjam_agent/request.rb', line 78 def add_line(severity, , ) @mutex.synchronize do if @bytes_all_lines > @max_bytes_all_lines unless @lines_dropped @lines << [severity, format_time(), "... [LINES DROPPED]"] @lines_dropped = true end return end = .strip line_too_long = .size > @max_line_length if line_too_long && severity < Logger::ERROR [(@max_line_length-21)..-1] = " ... [LINE TRUNCATED]" end if (@bytes_all_lines += .bytesize) > @max_bytes_all_lines if line_too_long [(@max_line_length-21)..-1] = " ... [LINE TRUNCATED]" end end @lines << [severity, format_time(), ] end end |
#caller_action ⇒ Object
70 71 72 |
# File 'lib/logjam_agent/request.rb', line 70 def caller_action @fields[:caller_action] end |
#caller_id ⇒ Object
66 67 68 |
# File 'lib/logjam_agent/request.rb', line 66 def caller_id @fields[:caller_id] end |
#forward ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/logjam_agent/request.rb', line 111 def forward return if @ignored || LogjamAgent.disabled engine = @fields.delete(:engine) sync = @fields.delete(:sync) @forwarder.forward(@fields, :engine => engine, :sync => sync) rescue Exception => e handle_forwarding_error(e) end |
#id ⇒ Object
58 59 60 |
# File 'lib/logjam_agent/request.rb', line 58 def id "#{@app}-#{@env}-#{@uuid}" end |
#ignore! ⇒ Object
50 51 52 |
# File 'lib/logjam_agent/request.rb', line 50 def ignore! @ignored = true end |
#ignored? ⇒ Boolean
54 55 56 |
# File 'lib/logjam_agent/request.rb', line 54 def ignored? @ignored end |
#trace_id ⇒ Object
74 75 76 |
# File 'lib/logjam_agent/request.rb', line 74 def trace_id @fields[:trace_id] end |