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.
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 |
# 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) unless (revision = LogjamAgent.application_revision).blank? @fields[:revision] = revision 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 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
51 52 53 |
# File 'lib/logjam_agent/request.rb', line 51 def action @fields[:action] end |
#add_exception(exception, severity = Logger::ERROR) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/logjam_agent/request.rb', line 78 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/logjam_agent/request.rb', line 63 def add_line(severity, , ) return if @bytes_all_lines > @max_bytes_all_lines = .strip if .size > @max_line_length && severity < Logger::ERROR [(@max_line_length-21)..-1] = " ... [LINE TRUNCATED]" end @mutex.synchronize do if (@bytes_all_lines += .bytesize) < @max_bytes_all_lines @lines << [severity, format_time(), ] else @lines << [severity, format_time(), "... [LINES DROPPED]"] end end end |
#caller_action ⇒ Object
59 60 61 |
# File 'lib/logjam_agent/request.rb', line 59 def caller_action @fields[:caller_action] end |
#caller_id ⇒ Object
55 56 57 |
# File 'lib/logjam_agent/request.rb', line 55 def caller_id @fields[:caller_id] end |
#forward ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/logjam_agent/request.rb', line 88 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
47 48 49 |
# File 'lib/logjam_agent/request.rb', line 47 def id "#{@app}-#{@env}-#{@uuid}" end |
#ignore! ⇒ Object
39 40 41 |
# File 'lib/logjam_agent/request.rb', line 39 def ignore! @ignored = true end |
#ignored? ⇒ Boolean
43 44 45 |
# File 'lib/logjam_agent/request.rb', line 43 def ignored? @ignored end |