Module: Akita::HarLogger

Defined in:
lib/akita/har_logger.rb,
lib/akita/har_logger/version.rb,
lib/akita/har_logger/har_entry.rb,
lib/akita/har_logger/har_utils.rb,
lib/akita/har_logger/http_request.rb,
lib/akita/har_logger/http_response.rb,
lib/akita/har_logger/writer_thread.rb

Defined Under Namespace

Classes: Filter, HarEntry, HarUtils, HttpRequest, HttpResponse, Middleware, WriterThread

Constant Summary collapse

VERSION =
"0.2.14"
@@default_file_name =
"akita_trace_#{Time.now.to_i}.har"
@@entry_queues =

Maps the name of each output file to a queue of entries to be logged to that file. The queue is used to ensure that event logging is thread-safe. The main thread will enqueue HarEntry objects. A HAR writer thread dequeues these objects and writes them to the output file.

{}
@@entry_queues_mutex =
Mutex.new

Class Method Summary collapse

Class Method Details

.default_file_nameObject



136
137
138
# File 'lib/akita/har_logger.rb', line 136

def self.default_file_name
  @@default_file_name
end

.get_queue(out_file_name) ⇒ Object

Returns the entry queue for the given file. If an entry queue doesn’t already exist, one is created and a HAR writer thread is started for the queue.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/akita/har_logger.rb', line 150

def self.get_queue(out_file_name)
  queue = nil
  Rails.logger.debug "AKITA: About to acquire entry-queue mutex "\
                     "#{@@entry_queues_mutex} in #{Thread.current}. "\
                     "Self-owned? #{@@entry_queues_mutex.owned?}"
  @@entry_queues_mutex.synchronize {
    begin
      Rails.logger.debug "AKITA: Acquired entry-queue mutex "\
                         "#{@@entry_queues_mutex} in #{Thread.current}."
      if @@entry_queues.has_key?(out_file_name) then
        return @@entry_queues[out_file_name]
      end

      queue = Queue.new
      @@entry_queues[out_file_name] = queue
    ensure
      Rails.logger.debug "AKITA: About to release entry-queue mutex "\
                         "#{@@entry_queues_mutex} in #{Thread.current}."
    end
  }

  WriterThread.new out_file_name, queue
  return queue
end

.instrument(config, har_file_name = nil) ⇒ Object

Adds HAR-logging instrumentation to a Rails application by adding to the top of the middleware stack.

Params:

config

the Rails::Application::Configuration associated with the Rails application being instrumented.

+har_file_name

the name of the HAR file to be produced. If the file exists, it will be overwritten.



17
18
19
# File 'lib/akita/har_logger.rb', line 17

def self.instrument(config, har_file_name = nil)
  config.middleware.unshift(Middleware, har_file_name)
end

.logException(context, e) ⇒ Object

Logs the given exception.



72
73
74
75
76
77
78
# File 'lib/akita/har_logger.rb', line 72

def self.logException(context, e)
  Rails.logger.debug "AKITA: Exception while #{context}: #{e.message} "\
                     "(#{e.class.name}) in thread #{Thread.current}"
  e.backtrace.each { |frame|
    Rails.logger.debug "AKITA:   #{frame}"
  }
end