forked from basecamp/kamal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac90ee0
commit 1cc5406
Showing
2 changed files
with
13 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
module Kamal::Commands::App::Logging | ||
def logs(container_id: nil, timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) | ||
pipe \ | ||
container_id ? "echo #{container_id}" : current_running_container_id, | ||
container_id_command(container_id), | ||
"xargs docker logs#{" --timestamps" if timestamps}#{" --since #{since}" if since}#{" --tail #{lines}" if lines} 2>&1", | ||
("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep) | ||
end | ||
|
||
def follow_logs(host:, container_id: nil, timestamps: true, lines: nil, grep: nil, grep_options: nil) | ||
run_over_ssh \ | ||
pipe( | ||
container_id ? "echo #{container_id}" : current_running_container_id, | ||
container_id_command(container_id), | ||
"xargs docker logs#{" --timestamps" if timestamps}#{" --tail #{lines}" if lines} --follow 2>&1", | ||
(%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep) | ||
), | ||
host: host | ||
end | ||
|
||
private | ||
|
||
def container_id_command(container_id) | ||
case container_id | ||
when Array then container_id | ||
when String, Symbol then "echo #{container_id}" | ||
else current_running_container_id | ||
end | ||
end | ||
end |