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