Skip to content

Commit

Permalink
Extract Logging too
Browse files Browse the repository at this point in the history
Leave only the core essentials in App
  • Loading branch information
dhh committed Sep 16, 2023
1 parent d303fcc commit 6b5c5f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
24 changes: 3 additions & 21 deletions lib/kamal/commands/app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Kamal::Commands::App < Kamal::Commands::Base
include Assets, Containers, Cord, Execution, Images
include Assets, Containers, Cord, Execution, Images, Logging

ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]

Expand Down Expand Up @@ -48,24 +48,6 @@ def info
end


def logs(since: nil, lines: nil, grep: nil)
pipe \
current_running_container_id,
"xargs docker logs#{" --since #{since}" if since}#{" --tail #{lines}" if lines} 2>&1",
("grep '#{grep}'" if grep)
end

def follow_logs(host:, grep: nil)
run_over_ssh \
pipe(
current_running_container_id,
"xargs docker logs --timestamps --tail 10 --follow 2>&1",
(%(grep "#{grep}") if grep)
),
host: host
end


def current_running_container_id
docker :ps, "--quiet", *filter_args(statuses: ACTIVE_DOCKER_STATUSES), "--latest"
end
Expand All @@ -90,7 +72,7 @@ def make_env_directory
end

def remove_env_file
[:rm, "-f", role_config.host_env_file_path]
[ :rm, "-f", role_config.host_env_file_path ]
end


Expand All @@ -104,7 +86,7 @@ def filter_args(statuses: nil)
end

def service_role_dest
[config.service, role, config.destination].compact.join("-")
[ config.service, role, config.destination ].compact.join("-")
end

def filters(statuses: nil)
Expand Down
18 changes: 18 additions & 0 deletions lib/kamal/commands/app/logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Kamal::Commands::App::Logging
def logs(since: nil, lines: nil, grep: nil)
pipe \
current_running_container_id,
"xargs docker logs#{" --since #{since}" if since}#{" --tail #{lines}" if lines} 2>&1",
("grep '#{grep}'" if grep)
end

def follow_logs(host:, grep: nil)
run_over_ssh \
pipe(
current_running_container_id,
"xargs docker logs --timestamps --tail 10 --follow 2>&1",
(%(grep "#{grep}") if grep)
),
host: host
end
end

0 comments on commit 6b5c5f0

Please sign in to comment.