]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
logging - output of leap command is now additionally sent to --log=FILE command line...
authorelijah <elijah@riseup.net>
Sat, 2 Feb 2013 09:43:03 +0000 (01:43 -0800)
committerelijah <elijah@riseup.net>
Sat, 2 Feb 2013 09:43:03 +0000 (01:43 -0800)
leap_cli.gemspec
lib/leap_cli/commands/pre.rb
lib/leap_cli/leapfile.rb
lib/leap_cli/log.rb

index 77d6dd173902e907ebcf23669e25ccc6a1224ee2..1b899bc3f247b835d79e5f0e273d721b51e16e5d 100644 (file)
@@ -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')
index 346814b60b9d2dbb22674df79ad2665f229a4267..26dce403eb7cecff639c8c679b72f847dc53b261 100644 (file)
@@ -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
 
@@ -39,6 +44,11 @@ module LeapCli
         bail! { log :missing, "platform directory '#{Path.platform}'" }
       end
 
+      #
+      # set log file
+      #
+      LeapCli.log_file = global[:log] || LeapCli.leapfile.log
+
       #
       # load all the nodes everything
       #
index f369c9a262eefb80a7c5a051d0676f65ab46a01a..439b60ce8a14ab9653801dc595fdd951ecf13c16 100644 (file)
@@ -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'))
index 0bc48a19b71d79ef3a34242fa1466b434a26b4ad..e1116934ed2c36e69c9debe476db4fef1bb51473 100644 (file)
@@ -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