Allow since as an option
And properly output/grep logs
This commit is contained in:
@@ -84,15 +84,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, aliases: "-n", default: 1000, desc: "Number of log lines to pull from each server"
|
option :since, aliases: "-s", default: "5m", desc: "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
||||||
|
option :lines, type: :numeric, aliases: "-n", desc: "Number of log lines to pull from each server"
|
||||||
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
option :grep, aliases: "-g", 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
|
||||||
|
|
||||||
|
since = options[:since]
|
||||||
lines = options[:lines]
|
lines = options[:lines]
|
||||||
grep = options[:grep]
|
grep = options[:grep]
|
||||||
|
|
||||||
on(MRSK.config.hosts) do |host|
|
on(MRSK.config.hosts) do |host|
|
||||||
begin
|
begin
|
||||||
puts "App Host: #{host}\n" + capture(*MRSK.app.logs(lines: lines, grep: grep), verbosity: Logger::INFO) + "\n\n"
|
puts "App Host: #{host}\n" + capture(*MRSK.app.logs(since: since, lines: lines, grep: grep), verbosity: Logger::INFO) + "\n\n"
|
||||||
rescue SSHKit::Command::Failed
|
rescue SSHKit::Command::Failed
|
||||||
puts "App Host: #{host}\nNothing found\n\n"
|
puts "App Host: #{host}\nNothing found\n\n"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
docker :ps, *service_filter
|
docker :ps, *service_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
def logs(lines: 1000, grep: nil)
|
def logs(since: "5m", lines: nil, grep: nil)
|
||||||
pipe \
|
pipe \
|
||||||
current_container_id,
|
current_container_id,
|
||||||
"xargs docker logs -n #{lines} -t",
|
"xargs docker logs --since #{since} -n #{lines} -t 2>&1",
|
||||||
("grep #{grep}" if grep)
|
("grep #{grep}" if grep)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user