Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tail -n 20 in pure Ruby #59

Merged
merged 1 commit into from
Aug 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/airbrussh/capistrano/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def deploy_failed
error_line(yellow("** Refer to #{log_file} for details. "\
"Here are the last 20 lines:"))
error_line
error_line(`tail -n 20 #{log_file.shellescape} 2>&1`)
error_line(tail_log_file)
end

private
Expand Down Expand Up @@ -75,6 +75,16 @@ def err_console
def error_line(line="\n")
line.each_line(&err_console.method(:print_line))
end

# Returns a String containing the last 20 lines of the log file. Since
# this method uses a fixed-size buffer, fewer than 20 lines may be
# returned in cases where the lines are extremely long.
def tail_log_file
open(log_file) do |file|
file.seek(-[8192, file.size].min, IO::SEEK_END)
file.readlines.last(20).join
end
end
end
end
end