Class: CloudwatchQuery::Parsers::RailsParser
- Defined in:
- lib/cloudwatch_query/parsers/rails_parser.rb
Constant Summary collapse
- BUILT_IN_SUB_PARSERS =
Built-in sub-parsers mapped to symbols
{ request: Rails::RequestSubParser, parameters: Rails::ParametersSubParser, redirect: Rails::RedirectSubParser, active_job: Rails::ActiveJobSubParser, processing: Rails::ProcessingSubParser, completed: Rails::CompletedSubParser }.freeze
- REQUEST_ID_REGEX =
Matches request UUID pattern: [abc-123-def-456]
/\[(?<request_id>[a-f0-9-]{36})\]/- SYSLOG_PREFIX_REGEX =
Matches syslog prefix: "Feb 4 22:37:47 ip-10-15-1-216 cryo:"
/^(?<syslog_timestamp>\w+\s+\d+\s+[\d:]+)\s+(?<server>[\w.-]+)\s+\w+\[(?<process_id>\d+)\]:\s*/
Instance Attribute Summary collapse
-
#sub_parsers ⇒ Object
readonly
Returns the value of attribute sub_parsers.
Class Method Summary collapse
-
.available_sub_parsers ⇒ Object
List available built-in sub-parser names.
- .matches?(message) ⇒ Boolean
- .parse(message) ⇒ Object
- .parser_name ⇒ Object
Instance Method Summary collapse
-
#initialize(*args) ⇒ RailsParser
constructor
Initialize with specific sub-parsers or use all defaults.
- #matches?(message) ⇒ Boolean
- #parse(message) ⇒ Object
Constructor Details
#initialize(*args) ⇒ RailsParser
Initialize with specific sub-parsers or use all defaults
41 42 43 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 41 def initialize(*args) @sub_parsers = resolve_sub_parsers(args) end |
Instance Attribute Details
#sub_parsers ⇒ Object (readonly)
Returns the value of attribute sub_parsers.
25 26 27 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 25 def sub_parsers @sub_parsers end |
Class Method Details
.available_sub_parsers ⇒ Object
List available built-in sub-parser names
87 88 89 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 87 def available_sub_parsers BUILT_IN_SUB_PARSERS.keys end |
.matches?(message) ⇒ Boolean
74 75 76 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 74 def matches?() new.matches?() end |
.parse(message) ⇒ Object
78 79 80 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 78 def parse() new.parse() end |
.parser_name ⇒ Object
82 83 84 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 82 def parser_name "rails" end |
Instance Method Details
#matches?(message) ⇒ Boolean
45 46 47 48 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 45 def matches?() # Must have a Rails request UUID pattern .match?(REQUEST_ID_REGEX) end |
#parse(message) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cloudwatch_query/parsers/rails_parser.rb', line 50 def parse() return nil unless matches?() base_data = extract_base_data() = strip_syslog_prefix() # Try each sub-parser until one matches sub_parser_data = {} @sub_parsers.each do |parser| if parser.matches?() sub_parser_data = parser.parse(, base_data) break if sub_parser_data[:line_type] end end # If no sub-parser matched, mark as unknown sub_parser_data[:line_type] ||= :unknown sub_parser_data[:raw_message] = if sub_parser_data[:line_type] == :unknown Rails::RailsLog.new(base_data.merge(sub_parser_data)) end |