Class: RequestLogAnalyzer::FileFormat::Base
- Inherits:
-
Object
- Object
- RequestLogAnalyzer::FileFormat::Base
- Extended by:
- ClassLevelInheritableAttributes
- 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, DelayedJob4, Haproxy, Merb, Mysql, Postgresql, Rails, Rails3, W3c
Constant Summary collapse
- Request =
Setup the default Request class.
::RequestLogAnalyzer::Request
Instance Attribute Summary collapse
-
#line_definitions ⇒ Object
readonly
Returns the value of attribute line_definitions.
-
#report_trackers ⇒ Object
readonly
Returns the value of attribute report_trackers.
Class Method Summary collapse
-
.create(*_args) ⇒ Object
Instantiation.
-
.format_definition(&_block) ⇒ Object
Specifies multiple line definitions at once using a block.
-
.line_definer ⇒ Object
Setup the default line definer.
-
.line_definition(name, &block) ⇒ Object
Specifies a single line defintions.
-
.report(mode = :append) {|report_definer| ... } ⇒ Object
Specifies the summary report using a block.
-
.report_definer ⇒ Object
Setup the default report definer.
Instance Method Summary collapse
-
#captures?(name) ⇒ Boolean
Returns true if this language captures the given symbol in one of its line definitions.
-
#initialize(line_definitions = {}, report_trackers = []) ⇒ Base
constructor
A new instance of Base.
- #line_divider ⇒ Object
-
#max_line_length ⇒ Object
Returns the max line length for this file format if any.
-
#parse_line(line, &warning_handler) ⇒ Object
Parses a line by trying to parse it using every line definition in this file format.
-
#request(*hashes) ⇒ Object
Returns a Request instance with the given parsed lines that should be provided as hashes.
-
#request_class ⇒ Object
Returns the Request class of this file format.
-
#setup_environment(_controller) ⇒ Object
Function that a file format con implement to monkey patch the environment.
-
#valid_line_definitions? ⇒ Boolean
Checks whether the line definitions form a valid language.
-
#valid_request_class? ⇒ Boolean
Checks whether the request class inherits from the base Request class.
-
#well_formed? ⇒ Boolean
(also: #valid?)
Checks whether the file format is valid so it can be safely used with RLA.
Methods included from ClassLevelInheritableAttributes
inheritable_attributes, inherited
Constructor Details
#initialize(line_definitions = {}, report_trackers = []) ⇒ Base
Returns a new instance of Base.
250 251 252 |
# File 'lib/request_log_analyzer/file_format.rb', line 250 def initialize(line_definitions = {}, report_trackers = []) @line_definitions, @report_trackers = line_definitions, report_trackers end |
Instance Attribute Details
#line_definitions ⇒ Object (readonly)
Returns the value of attribute line_definitions.
202 203 204 |
# File 'lib/request_log_analyzer/file_format.rb', line 202 def line_definitions @line_definitions end |
#report_trackers ⇒ Object (readonly)
Returns the value of attribute report_trackers.
202 203 204 |
# File 'lib/request_log_analyzer/file_format.rb', line 202 def report_trackers @report_trackers end |
Class Method Details
.create(*_args) ⇒ Object
Instantiation
245 246 247 248 |
# File 'lib/request_log_analyzer/file_format.rb', line 245 def self.create(*_args) # Ignore arguments new(line_definer.line_definitions, report_definer.trackers) end |
.format_definition(&_block) ⇒ Object
Specifies multiple line definitions at once using a block
214 215 216 217 218 219 220 |
# File 'lib/request_log_analyzer/file_format.rb', line 214 def self.format_definition(&_block) if block_given? yield line_definer else return line_definer end end |
.line_definer ⇒ Object
Setup the default line definer.
229 230 231 |
# File 'lib/request_log_analyzer/file_format.rb', line 229 def self.line_definer @line_definer ||= ::RequestLogAnalyzer::LineDefinition::Definer.new end |
.line_definition(name, &block) ⇒ Object
Specifies a single line defintions.
209 210 211 |
# File 'lib/request_log_analyzer/file_format.rb', line 209 def self.line_definition(name, &block) line_definer.define_line(name, &block) end |
.report(mode = :append) {|report_definer| ... } ⇒ Object
Specifies the summary report using a block.
223 224 225 226 |
# File 'lib/request_log_analyzer/file_format.rb', line 223 def self.report(mode = :append, &_block) report_definer.reset! if mode == :overwrite yield(report_definer) end |
.report_definer ⇒ Object
Setup the default report definer.
234 235 236 |
# File 'lib/request_log_analyzer/file_format.rb', line 234 def self.report_definer @report_definer ||= ::RequestLogAnalyzer::Aggregator::Summarizer::Definer.new end |
Instance Method Details
#captures?(name) ⇒ Boolean
Returns true if this language captures the given symbol in one of its line definitions
287 288 289 |
# File 'lib/request_log_analyzer/file_format.rb', line 287 def captures?(name) line_definitions.any? { |(_, ld)| ld.captures?(name) } end |
#line_divider ⇒ Object
311 312 313 |
# File 'lib/request_log_analyzer/file_format.rb', line 311 def line_divider self.class.const_get(LINE_DIVIDER) if self.class.const_defined?(:LINE_DIVIDER) end |
#max_line_length ⇒ Object
Returns the max line length for this file format if any.
307 308 309 |
# File 'lib/request_log_analyzer/file_format.rb', line 307 def max_line_length self.class.const_get(MAX_LINE_LENGTH) if self.class.const_defined?(:MAX_LINE_LENGTH) end |
#parse_line(line, &warning_handler) ⇒ Object
Parses a line by trying to parse it using every line definition in this file format
297 298 299 300 301 302 303 304 |
# File 'lib/request_log_analyzer/file_format.rb', line 297 def parse_line(line, &warning_handler) line_definitions.each do |_lt, definition| match = definition.matches(line, &warning_handler) return match if match end nil end |
#request(*hashes) ⇒ Object
Returns a Request instance with the given parsed lines that should be provided as hashes.
264 265 266 |
# File 'lib/request_log_analyzer/file_format.rb', line 264 def request(*hashes) request_class.create(self, *hashes) end |
#request_class ⇒ Object
Returns the Request class of this file format
259 260 261 |
# File 'lib/request_log_analyzer/file_format.rb', line 259 def request_class self.class::Request end |
#setup_environment(_controller) ⇒ Object
Function that a file format con implement to monkey patch the environment.
-
controllerThe environment is provided as a controller instance
293 294 |
# File 'lib/request_log_analyzer/file_format.rb', line 293 def setup_environment(_controller) end |
#valid_line_definitions? ⇒ Boolean
Checks whether the line definitions form a valid language. A file format should have at least a header and a footer line type
277 278 279 |
# File 'lib/request_log_analyzer/file_format.rb', line 277 def valid_line_definitions? line_definitions.any? { |(_, ld)| ld.header } && line_definitions.any? { |(_, ld)| ld. } end |
#valid_request_class? ⇒ Boolean
Checks whether the request class inherits from the base Request class.
282 283 284 |
# File 'lib/request_log_analyzer/file_format.rb', line 282 def valid_request_class? request_class.ancestors.include?(RequestLogAnalyzer::Request) end |
#well_formed? ⇒ Boolean Also known as: valid?
Checks whether the file format is valid so it can be safely used with RLA.
269 270 271 |
# File 'lib/request_log_analyzer/file_format.rb', line 269 def well_formed? valid_line_definitions? && valid_request_class? end |