Class: RequestLogAnalyzer::FileFormat::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/request_log_analyzer/file_format.rb

Overview

Base class for all log file format definitions. This class provides functions for subclasses to define their LineDefinitions and to define a summary report.

A subclass of this class is instantiated when request-log-analyzer is started and this instance is shared with all components of the application so they can act on the specifics of the format

Direct Known Subclasses

AmazonS3, Apache, DelayedJob, DelayedJob2, DelayedJob21, DelayedJob3, Haproxy, Merb, Mysql, Postgresql, Rails, Rails3, W3c

Constant Summary

Request =

Setup the default Request class.

::RequestLogAnalyzer::Request

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(line_definitions = OrderedHash.new, report_trackers = [])

Returns a new instance of Base



251
252
253
# File 'lib/request_log_analyzer/file_format.rb', line 251

def initialize(line_definitions = OrderedHash.new, report_trackers = [])
  @line_definitions, @report_trackers = line_definitions, report_trackers
end

Instance Attribute Details

- (Object) line_definitions (readonly)

Returns the value of attribute line_definitions



203
204
205
# File 'lib/request_log_analyzer/file_format.rb', line 203

def line_definitions
  @line_definitions
end

- (Object) report_trackers (readonly)

Returns the value of attribute report_trackers



203
204
205
# File 'lib/request_log_analyzer/file_format.rb', line 203

def report_trackers
  @report_trackers
end

Class Method Details

+ (Object) create(*args)

Instantiation



246
247
248
249
# File 'lib/request_log_analyzer/file_format.rb', line 246

def self.create(*args)
  # Ignore arguments
  return self.new(line_definer.line_definitions, report_definer.trackers)
end

+ (Object) format_definition(&block)

Specifies multiple line definitions at once using a block



215
216
217
218
219
220
221
# File 'lib/request_log_analyzer/file_format.rb', line 215

def self.format_definition(&block)
  if block_given?
    yield self.line_definer
  else
    return self.line_definer
  end
end

+ (Object) line_definer

Setup the default line definer.



230
231
232
# File 'lib/request_log_analyzer/file_format.rb', line 230

def self.line_definer
  @line_definer ||= ::RequestLogAnalyzer::LineDefinition::Definer.new
end

+ (Object) line_definition(name, &block)

Specifies a single line defintions.



210
211
212
# File 'lib/request_log_analyzer/file_format.rb', line 210

def self.line_definition(name, &block)
  line_definer.define_line(name, &block)
end

+ (Object) report(mode = :append) {|self.report_definer| ... }

Specifies the summary report using a block.

Yields:



224
225
226
227
# File 'lib/request_log_analyzer/file_format.rb', line 224

def self.report(mode = :append, &block)
  self.report_definer.reset! if mode == :overwrite
  yield(self.report_definer)
end

+ (Object) report_definer

Setup the default report definer.



235
236
237
# File 'lib/request_log_analyzer/file_format.rb', line 235

def self.report_definer
  @report_definer ||= ::RequestLogAnalyzer::Aggregator::Summarizer::Definer.new
end

Instance Method Details

- (Boolean) captures?(name)

Returns true if this language captures the given symbol in one of its line definitions

Returns:

  • (Boolean)


289
290
291
# File 'lib/request_log_analyzer/file_format.rb', line 289

def captures?(name)
  line_definitions.any? { |(_, ld)| ld.captures?(name) }
end

- (Object) line_divider



313
314
315
# File 'lib/request_log_analyzer/file_format.rb', line 313

def line_divider
  self.class.const_get(LINE_DIVIDER) if self.class.const_defined?(:LINE_DIVIDER)
end

- (Object) max_line_length

Returns the max line length for this file format if any.



309
310
311
# File 'lib/request_log_analyzer/file_format.rb', line 309

def max_line_length
  self.class.const_get(MAX_LINE_LENGTH) if self.class.const_defined?(:MAX_LINE_LENGTH)
end

- (Object) parse_line(line, &warning_handler)

Parses a line by trying to parse it using every line definition in this file format



299
300
301
302
303
304
305
306
# File 'lib/request_log_analyzer/file_format.rb', line 299

def parse_line(line, &warning_handler)
  self.line_definitions.each do |lt, definition|
    match = definition.matches(line, &warning_handler)
    return match if match
  end

  return nil
end

- (Object) request(*hashes)

Returns a Request instance with the given parsed lines that should be provided as hashes.



265
266
267
# File 'lib/request_log_analyzer/file_format.rb', line 265

def request(*hashes)
  request_class.create(self, *hashes)
end

- (Object) request_class

Returns the Request class of this file format



260
261
262
# File 'lib/request_log_analyzer/file_format.rb', line 260

def request_class
  self.class::Request
end

- (Object) setup_environment(controller)

Function that a file format con implement to monkey patch the environment.

  • controller The environment is provided as a controller instance



295
296
# File 'lib/request_log_analyzer/file_format.rb', line 295

def setup_environment(controller)
end

- (Boolean) valid_line_definitions?

Checks whether the line definitions form a valid language. A file format should have at least a header and a footer line type

Returns:

  • (Boolean)


279
280
281
# File 'lib/request_log_analyzer/file_format.rb', line 279

def valid_line_definitions?
  line_definitions.any? { |(_, ld)| ld.header } && line_definitions.any? { |(_, ld)| ld.footer }
end

- (Boolean) valid_request_class?

Checks whether the request class inherits from the base Request class.

Returns:

  • (Boolean)


284
285
286
# File 'lib/request_log_analyzer/file_format.rb', line 284

def valid_request_class?
  request_class.ancestors.include?(RequestLogAnalyzer::Request)
end

- (Boolean) well_formed? Also known as: valid?

Checks whether the file format is valid so it can be safely used with RLA.

Returns:

  • (Boolean)


270
271
272
# File 'lib/request_log_analyzer/file_format.rb', line 270

def well_formed?
  valid_line_definitions? && valid_request_class?
end