Class: Tidewave::Tools::GetLogs
- Defined in:
- lib/tidewave/tools/get_logs.rb
Instance Method Summary collapse
Instance Method Details
#call(tail:, grep: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tidewave/tools/get_logs.rb', line 16 def call(tail:, grep: nil) log_file = Rails.root.join("log", "#{Rails.env}.log") return "Log file not found" unless File.exist?(log_file) regex = Regexp.new(grep, Regexp::IGNORECASE) if grep matching_lines = [] tail_lines(log_file) do |line| if regex.nil? || line.match?(regex) matching_lines.unshift(line) break if matching_lines.size >= tail end end matching_lines.join end |