Class: Ask::Rails::Harness::Tools::ReadLog
- Inherits:
-
Ask::Rails::Harness::Tool
- Object
- Tool
- Ask::Rails::Harness::Tool
- Ask::Rails::Harness::Tools::ReadLog
- Defined in:
- lib/ask/rails/harness/tools/read_log.rb
Constant Summary collapse
- MAX_LINES =
500- LEVEL_PATTERNS =
{ "ERROR" => /\bERROR\b/i, "WARN" => /\bWARN\b/i, "INFO" => /\bINFO\b/i, "DEBUG" => /\bDEBUG\b/i }.freeze
Instance Method Summary collapse
Methods inherited from Ask::Rails::Harness::Tool
#call, #rails_root, session_id, session_id=
Instance Method Details
#execute(lines: 50, level: nil, search: nil, file: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ask/rails/harness/tools/read_log.rb', line 24 def execute(lines: 50, level: nil, search: nil, file: nil) max_lines = [lines.to_i, MAX_LINES].min log_path = resolve_log_path(file) unless log_path.exist? return Ask::Result.failure( "Log file not found: #{log_path}. The application may not have written any logs yet." ) end raw_lines = read_all_log_files(log_path) return { lines: [], total_lines: 0, path: log_path.to_s } if raw_lines.empty? filtered = apply_filters(raw_lines, level: level, search: search) recent = filtered.last(max_lines).map(&:chomp) { lines: recent, total_lines: raw_lines.size, matched_lines: filtered.size, path: log_path.to_s, filters_applied: { level: level, search: search }.compact } end |