Skip to content

Commit

Permalink
Merge pull request #7 from piotr-iohk/number_of_lines_in_tail
Browse files Browse the repository at this point in the history
Number of lines in tail
  • Loading branch information
piotr-iohk authored Mar 1, 2023
2 parents 2ccf4c6 + 89670b3 commit 3064079
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions bin/cardano-up
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ doc = <<~DOCOPT
#{File.basename(__FILE__)} ls
#{File.basename(__FILE__)} config [--set-default] [--bindir <path>] [--configdir <path>] [--logdir <path>] [--statedir <path>]
#{File.basename(__FILE__)} <env> [(node|wallet)] [(up|down|ping)] [--port <port>] [--session <name>]
#{File.basename(__FILE__)} <env> (node|wallet) tail [--session <name>]
#{File.basename(__FILE__)} <env> (node|wallet) tail [--lines <num_lines>] [--session <name>]
#{File.basename(__FILE__)} -v | --version
#{File.basename(__FILE__)} -e | --examples
#{File.basename(__FILE__)} -h | --help
Expand All @@ -29,6 +29,7 @@ doc = <<~DOCOPT
ones from latest release.
down Stop particular service.
tail Follow logs for particular service.
-n --lines <num_lines> Number of lines to show from the end of the log file. [default: 10]
ping Ping service to check its status.
ls List sessions.
-p --port <port> Specify wallet port. [default: 8090]
Expand Down Expand Up @@ -122,7 +123,7 @@ Check health of node and wallet on mainnet:
Monitor mainnet wallet and node logs (Ctrl + c to stop):
$ #{File.basename(__FILE__)} mainnet node tail
$ #{File.basename(__FILE__)} mainnet wallet tail
$ #{File.basename(__FILE__)} mainnet wallet tail -n 100
Stop preprod node:
Expand Down Expand Up @@ -316,14 +317,15 @@ Stop mainnet node and wallet:
elsif o['tail'] == true
env = o['<env>']
session_name = o['--session']
lines = o['--lines'].to_i
begin
log_dir = File.join(CardanoUp.config[:log_dir], session_name, env)
if o['node']
log_file = File.join(log_dir, 'node.log')
CardanoUp::Tail.tail(log_file)
CardanoUp::Tail.tail(log_file, lines)
elsif o['wallet']
log_file = File.join(log_dir, 'wallet.log')
CardanoUp::Tail.tail(log_file)
CardanoUp::Tail.tail(log_file, lines)
end
rescue CardanoUp::EnvNotSupportedError => e
warn(e.message)
Expand Down
5 changes: 3 additions & 2 deletions lib/cardano-up/tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
module CardanoUp
# Tail log file
module Tail
def self.tail(file_path)
def self.tail(file_path, lines = nil)
lines_back = lines || 10
File.open(file_path) do |log|
log.extend(File::Tail)
log.interval
log.backward(10)
log.backward(lines_back.to_i)
log.tail { |line| warn line }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cardano-up/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Version
module CardanoUp
VERSION ||= '0.1.3'
VERSION ||= '0.1.4'
end

0 comments on commit 3064079

Please sign in to comment.