diff options
author | elijah <elijah@riseup.net> | 2013-02-02 01:43:03 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-02-02 01:43:03 -0800 |
commit | 05494b7861e7883d273d42c30a7bc799c5384873 (patch) | |
tree | 32fc8776a0e25ff257e423ac4e0b4f61abc7cf6c | |
parent | d0247e01c08cf2ce0fefb5808f11c824b681d61f (diff) | |
download | leap_cli-05494b7861e7883d273d42c30a7bc799c5384873.tar.gz leap_cli-05494b7861e7883d273d42c30a7bc799c5384873.tar.bz2 |
logging - output of leap command is now additionally sent to --log=FILE command line switch or @log value in Leapfile.
-rw-r--r-- | leap_cli.gemspec | 1 | ||||
-rw-r--r-- | lib/leap_cli/commands/pre.rb | 12 | ||||
-rw-r--r-- | lib/leap_cli/leapfile.rb | 1 | ||||
-rw-r--r-- | lib/leap_cli/log.rb | 18 |
4 files changed, 30 insertions, 2 deletions
diff --git a/leap_cli.gemspec b/leap_cli.gemspec index 77d6dd1..1b899bc 100644 --- a/leap_cli.gemspec +++ b/leap_cli.gemspec @@ -50,6 +50,7 @@ spec = Gem::Specification.new do |s| s.add_runtime_dependency('command_line_reporter') s.add_runtime_dependency('highline') s.add_runtime_dependency('paint') + s.add_runtime_dependency('tee') # network gems s.add_runtime_dependency('capistrano', '>= 2.13.5') diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb index 346814b..26dce40 100644 --- a/lib/leap_cli/commands/pre.rb +++ b/lib/leap_cli/commands/pre.rb @@ -6,10 +6,15 @@ module LeapCli module Commands desc 'Verbosity level 0..2' - arg_name 'level' + arg_name 'LEVEL' default_value '1' flag [:v, :verbose] + desc 'Override default log file' + arg_name 'FILE' + default_value nil + flag :log + desc 'Display version number and exit' switch :version, :negatable => false @@ -40,6 +45,11 @@ module LeapCli end # + # set log file + # + LeapCli.log_file = global[:log] || LeapCli.leapfile.log + + # # load all the nodes everything # manager diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb index f369c9a..439b60c 100644 --- a/lib/leap_cli/leapfile.rb +++ b/lib/leap_cli/leapfile.rb @@ -14,6 +14,7 @@ module LeapCli attr_accessor :provider_directory_path attr_accessor :custom_vagrant_vm_line attr_accessor :leap_version + attr_accessor :log def load directory = File.expand_path(find_in_directory_tree('Leapfile')) diff --git a/lib/leap_cli/log.rb b/lib/leap_cli/log.rb index 0bc48a1..e111693 100644 --- a/lib/leap_cli/log.rb +++ b/lib/leap_cli/log.rb @@ -1,4 +1,5 @@ require 'paint' +require 'tee' ## ## LOGGING @@ -23,6 +24,21 @@ module LeapCli def indent_level=(value) @indent_level = value end + + def log_file + @log_file + end + def log_file=(value) + @log_file = value + if value + @log_output_stream = Tee.open(@log_file, :mode => 'a') + end + end + + def log_output_stream + @log_output_stream || STDOUT + end + end @@ -92,7 +108,7 @@ module LeapCli line += "[%s] " % options[:host] end line += "#{message}\n" - print line + LeapCli.log_output_stream.print(line) if block_given? LeapCli.indent_level += 1 yield |