Class: RailsLogParser::Parser
- Inherits:
-
Object
- Object
- RailsLogParser::Parser
- Defined in:
- lib/rails_log_parser/parser.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#last_action ⇒ Object
readonly
Returns the value of attribute last_action.
-
#not_parseable_lines ⇒ Object
readonly
Returns the value of attribute not_parseable_lines.
Class Method Summary collapse
Instance Method Summary collapse
- #action(type, params) ⇒ Object
- #actions ⇒ Object
- #active_job(params) ⇒ Object
- #add_message(params) ⇒ Object
- #delayed_job(params) ⇒ Object
- #empty_line(params) ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #puts(line) ⇒ Object
- #request(params) ⇒ Object
- #summary(last_minutes: nil) ⇒ Object
- #without_request(params) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
24 25 26 27 28 29 30 |
# File 'lib/rails_log_parser/parser.rb', line 24 def initialize config_file = File.join(Dir.pwd,'config/rails_log_parser.rb') require config_file if File.file?(config_file) @actions = {} @not_parseable_lines = RailsLogParser::NotParseableLines.new end |
Class Attribute Details
.log_path ⇒ Object
7 8 9 |
# File 'lib/rails_log_parser/parser.rb', line 7 def log_path @log_path || ENV['LOG_PATH'] || raise('no log_path given') end |
Instance Attribute Details
#last_action ⇒ Object (readonly)
Returns the value of attribute last_action.
22 23 24 |
# File 'lib/rails_log_parser/parser.rb', line 22 def last_action @last_action end |
#not_parseable_lines ⇒ Object (readonly)
Returns the value of attribute not_parseable_lines.
22 23 24 |
# File 'lib/rails_log_parser/parser.rb', line 22 def not_parseable_lines @not_parseable_lines end |
Class Method Details
.from_file(path) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/rails_log_parser/parser.rb', line 11 def from_file(path) parser = new File.open(path, 'r') do |handle| while (line = handle.gets) parser.puts(line) end end parser end |
Instance Method Details
#action(type, params) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/rails_log_parser/parser.rb', line 67 def action(type, params) @actions[params['id']] ||= RailsLogParser::Action.new(type, params['id']) @actions[params['id']].severity = params['severity_label'] @actions[params['id']].datetime = params['datetime'] @actions[params['id']].(params['message']) unless params['message'].nil? @last_action = @actions[params['id']] end |
#actions ⇒ Object
59 60 61 |
# File 'lib/rails_log_parser/parser.rb', line 59 def actions @actions.values end |
#active_job(params) ⇒ Object
91 92 93 |
# File 'lib/rails_log_parser/parser.rb', line 91 def active_job(params) action(:active_job, params) end |
#add_message(params) ⇒ Object
99 100 101 102 |
# File 'lib/rails_log_parser/parser.rb', line 99 def (params) @actions[params['id']] ||= RailsLogParser::Action.new(type, params['id']) @actions[params['id']].(params['message']) end |
#delayed_job(params) ⇒ Object
95 96 97 |
# File 'lib/rails_log_parser/parser.rb', line 95 def delayed_job(params) action(:delayed_job, params) end |
#empty_line(params) ⇒ Object
79 80 81 82 83 |
# File 'lib/rails_log_parser/parser.rb', line 79 def empty_line(params) params = params.named_captures params['message'] = nil action(:request, params) end |
#puts(line) ⇒ Object
63 64 65 |
# File 'lib/rails_log_parser/parser.rb', line 63 def puts(line) RailsLogParser::Line.new(self, line.encode('UTF-8', invalid: :replace)) end |
#request(params) ⇒ Object
75 76 77 |
# File 'lib/rails_log_parser/parser.rb', line 75 def request(params) action(:request, params) end |
#summary(last_minutes: nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rails_log_parser/parser.rb', line 33 def summary(last_minutes: nil) relevant = actions if last_minutes.present? from = last_minutes.to_i.minutes.ago relevant = relevant.select { |a| a.after?(from) } end summary_output = [] if @not_parseable_lines.lines.present? summary_output.push('Not parseable lines:') summary_output += @not_parseable_lines.lines.map { |line| " #{line}" } summary_output.push("\n\n") @not_parseable_lines.save end %i[warn error fatal].each do |severity| selected = relevant.select { |a| a.public_send("#{severity}?") }.reject(&:known_exception?).reject(&:ignore?) next if selected.blank? summary_output.push("#{selected.count} lines with #{severity}:") summary_output += selected.map(&:headline).map { |line| " #{line}" } summary_output.push("\n\n") end summary_output.join("\n") end |
#without_request(params) ⇒ Object
85 86 87 88 89 |
# File 'lib/rails_log_parser/parser.rb', line 85 def without_request(params) params = params.named_captures params['id'] = SecureRandom.uuid action(:without_request, params) end |