Add grep and line configuration to logs
This commit is contained in:
@@ -79,9 +79,19 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc "logs", "Show last 100 log lines from app on servers"
|
desc "logs", "Show last 100 log lines from app on servers"
|
||||||
|
option :lines, type: :numeric, default: 100, desc: "Number of log lines to pull from each server"
|
||||||
|
option :grep, desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
||||||
def logs
|
def logs
|
||||||
# FIXME: Catch when app containers aren't running
|
# FIXME: Catch when app containers aren't running
|
||||||
on(MRSK.config.hosts) { |host| puts "App Host: #{host}\n" + capture(*MRSK.app.logs) + "\n\n" }
|
lines = options[:lines]
|
||||||
|
grep = options[:grep]
|
||||||
|
on(MRSK.config.hosts) do |host|
|
||||||
|
begin
|
||||||
|
puts "App Host: #{host}\n" + capture(*MRSK.app.logs(lines: lines, grep: grep), verbosity: Logger::INFO) + "\n\n"
|
||||||
|
rescue SSHKit::Command::Failed
|
||||||
|
puts "App Host: #{host}\nNothing found\n\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "remove", "Remove app containers and images from servers"
|
desc "remove", "Remove app containers and images from servers"
|
||||||
|
|||||||
@@ -27,8 +27,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
docker :ps, *service_filter
|
docker :ps, *service_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
def logs
|
def logs(lines: 100, grep: nil)
|
||||||
[ "docker ps -q #{service_filter.join(" ")} | xargs docker logs -n 100 -t" ]
|
[ "docker ps -q #{service_filter.join(" ")} | xargs docker logs -n #{lines} -t" ].tap do |command|
|
||||||
|
command.first << " | grep #{grep}" if grep
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec(*command, interactive: false)
|
def exec(*command, interactive: false)
|
||||||
|
|||||||
Reference in New Issue
Block a user