<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -66,7 +66,46 @@ This will create an initial &quot;config/schedule.rb&quot; file you.
   end
 
 More examples on the wiki: http://wiki.github.com/javan/whenever/instructions-and-examples
+
+== Output redirection
+
+In your schedule.rb file you can specify the redirection options for your commands at a global or command level by setting the 'output' variable.
+
+  # adds &quot;&gt;&gt; /path/to/file.log 2&gt;&amp;1&quot; to all commands
+  set :output =&gt; '/path/to/file.log'
+
+Or you can STDOUT and STDERR separately,
+
+  # adds &quot;&gt;&gt; cron.log 2&gt; error.log&quot; to all commands
+  set :output =&gt; {:error =&gt; 'error.log', :standard =&gt; 'cron.log'}
+  
+  # adds &quot;&gt;&gt; cron.log&quot; to all commands
+  set :output =&gt; {:standard =&gt; 'cron.log'}
   
+  # adds &quot;2&gt; error.log&quot; to all commands
+  set :output =&gt; {:error =&gt; 'error.log'}
+
+Additionally you can set these values at the command level,
+
+  every 3.hours do
+    runner &quot;MyModel.some_process&quot;, :output =&gt; 'cron.log'     
+    rake &quot;my:rake:task&quot;, :output =&gt; {:error =&gt; 'error.log', :standard =&gt; 'cron.log'}
+    command &quot;/usr/bin/cmd&quot;
+  end  
+
+In all cases you can if you explicitly set the value of any output to 'nil' it will add a redirect to /dev/null
+
+  # adds &quot;&gt;&gt; /dev/null 2&gt;&amp;1&quot; to all commands
+  set :output =&gt; nil
+  set :output =&gt; {:error =&gt; nil, :standard =&gt; nil}
+
+  # adds &quot;&gt;&gt; /dev/null&quot; to all commands
+  set :output =&gt; {:standard =&gt; nil}
+
+  # adds &quot;2&gt; /dev/null&quot; to all commands
+  set :output =&gt; {:error =&gt; nil}
+
+
 == Cron output
 
   $ cd /my/rails/app</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -36,7 +36,9 @@ content = &lt;&lt;-FILE
 
 # Example:
 #
-# set :cron_log, &quot;/path/to/my/cron_log.log&quot;
+# set :output, &quot;/path/to/my/cron_log.log&quot;
+# set :output, {:error =&gt; '/path/to/error.log', :standard =&gt; '/path/to/cron.log'}
+# set :output, {:error =&gt; '/path/to/error.log', :standard =&gt; nil}
 #
 # every 2.hours do
 #   command &quot;/usr/bin/some_great_command&quot;</diff>
      <filename>bin/wheneverize</filename>
    </modified>
    <modified>
      <diff>@@ -38,7 +38,8 @@ module Whenever
     end
     
     def command(task, options = {})
-      options[:cron_log] ||= @cron_log unless options[:cron_log] === false
+      @output = :unset unless defined?(@output)
+      options[:output]   ||= options.has_key?(:output) ? options[:output] : @output
       options[:class]    ||= Whenever::Job::Default
       @jobs[@current_time_scope] ||= []
       @jobs[@current_time_scope] &lt;&lt; options[:class].new(@options.merge(:task =&gt; task).merge(options))
@@ -140,7 +141,7 @@ module Whenever
       @jobs.each do |time, jobs|
         jobs.each do |job|
           Whenever::Output::Cron.output(time, job) do |cron|
-            cron &lt;&lt; &quot; &gt;&gt; #{job.cron_log} 2&gt;&amp;1&quot; if job.cron_log 
+            cron &lt;&lt; job.redirect_output 
             cron &lt;&lt; &quot;\n\n&quot;
             
             if cron.starts_with?(&quot;@&quot;)</diff>
      <filename>lib/job_list.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,12 +2,12 @@ module Whenever
   module Job
     class Default
       
-      attr_accessor :task, :at, :cron_log
+      attr_accessor :task, :at, :redirect
     
       def initialize(options = {})
         @task        = options[:task]
         @at          = options[:at]
-        @cron_log    = options[:cron_log]
+        @redirect    = options[:output]
         @environment = options[:environment] || :production
         @path        = options[:path] || Whenever.path
       end
@@ -16,8 +16,50 @@ module Whenever
         task
       end
       
+      def redirect_output
+        case @redirect
+        when String
+          redirect_from_string
+        when Hash
+          redirect_from_hash
+        when NilClass
+          &quot; &gt;&gt; /dev/null 2&gt;&amp;1&quot;
+        else
+          ''
+        end 
+      end
+      
     protected
       
+      def stdout
+        return unless @redirect.has_key?(:standard)
+        @redirect[:standard].nil? ? '/dev/null' : @redirect[:standard]
+      end
+      
+      def stderr
+        return unless @redirect.has_key?(:error)
+        @redirect[:error].nil? ? '/dev/null' : @redirect[:error]
+      end
+      
+      def redirect_from_hash
+        case
+        when stdout == '/dev/null' &amp;&amp; stderr == '/dev/null'
+          &quot; &gt;&gt; /dev/null 2&gt;&amp;1&quot;
+        when stdout &amp;&amp; stderr
+          &quot; &gt;&gt; #{stdout} 2&gt; #{stderr}&quot;
+        when stderr
+          &quot; 2&gt; #{stderr}&quot;
+        when stdout
+          &quot; &gt;&gt; #{stdout}&quot;
+        else
+          ''
+        end
+      end
+      
+      def redirect_from_string
+        &quot; &gt;&gt; #{@redirect} 2&gt;&amp;1&quot;
+      end
+      
       def path_required
         raise ArgumentError, &quot;No path available; set :path, '/your/path' in your schedule file&quot; if @path.blank?
       end</diff>
      <filename>lib/job_types/default.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,11 +17,28 @@ class OutputCommandTest &lt; Test::Unit::TestCase
     end
   end
   
-  context &quot;A command when the cron_log is set&quot; do
+  context &quot;An every statement with two commands in it&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 1.hour do
+          command &quot;first&quot;
+          command &quot;second&quot;
+        end
+      file
+    end
+
+    should &quot;output both commands&quot; do
+      assert_match &quot;0 * * * * first&quot;, @output
+      assert_match &quot;0 * * * * second&quot;, @output
+    end
+  end
+
+  context &quot;A command when the output is set to nil&quot; do
     setup do
       @output = Whenever.cron \
       &lt;&lt;-file
-        set :cron_log, 'logfile.log'
+        set :output, nil
         every 2.hours do
           command &quot;blahblah&quot;
         end
@@ -29,34 +46,83 @@ class OutputCommandTest &lt; Test::Unit::TestCase
     end
     
     should &quot;output the command with the log syntax appended&quot; do
-      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; logfile.log 2&gt;&amp;1$/, @output
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; \/dev\/null 2&gt;&amp;1$/, @output
     end
   end
+
   
-  context &quot;A command when the cron_log is set and the comand overrides it&quot; do
+  context &quot;A command when the output is set&quot; do
     setup do
       @output = Whenever.cron \
       &lt;&lt;-file
-        set :cron_log, 'logfile.log'
+        set :output, 'logfile.log'
         every 2.hours do
-          command &quot;blahblah&quot;, :cron_log =&gt; 'otherlog.log'
+          command &quot;blahblah&quot;
         end
       file
     end
     
     should &quot;output the command with the log syntax appended&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; logfile.log 2&gt;&amp;1$/, @output
+    end
+  end
+
+  context &quot;A command when the error and standard output is set by the command&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:standard =&gt; 'dev_null', :error =&gt; 'dev_err'}
+        end
+      file
+    end
+
+    should &quot;output the command without the log syntax appended&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; dev_null 2&gt; dev_err$/, @output
+    end
+  end
+  
+  context &quot;A command when the output is set and the comand overrides it&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        set :output, 'logfile.log'
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; 'otherlog.log'
+        end
+      file
+    end
+    
+    should &quot;output the command with the command syntax appended&quot; do
       assert_no_match /.+ .+ .+ .+ blahblah &gt;&gt; logfile.log 2&gt;&amp;1/, @output
       assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; otherlog.log 2&gt;&amp;1$/, @output
     end
   end
-  
-  context &quot;A command when the cron_log is set and the comand rejects it&quot; do
+
+  context &quot;A command when the output is set and the comand overrides with standard and error&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        set :output, 'logfile.log'
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:error =&gt; 'dev_err', :standard =&gt; 'dev_null' }
+        end
+      file
+    end
+    
+    should &quot;output the command with the overridden redirection syntax appended&quot; do
+      assert_no_match /.+ .+ .+ .+ blahblah &gt;&gt; logfile.log 2&gt;&amp;1/, @output
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; dev_null 2&gt; dev_err$/, @output
+    end
+  end
+
+  context &quot;A command when the output is set and the comand rejects it&quot; do
     setup do
       @output = Whenever.cron \
       &lt;&lt;-file
-        set :cron_log, 'logfile.log'
+        set :output, 'logfile.log'
         every 2.hours do
-          command &quot;blahblah&quot;, :cron_log =&gt; false
+          command &quot;blahblah&quot;, :output =&gt; false
         end
       file
     end
@@ -67,11 +133,11 @@ class OutputCommandTest &lt; Test::Unit::TestCase
     end
   end
   
-  context &quot;A command when the cron_log is set and is overridden by the :set option&quot; do
+  context &quot;A command when the output is set and is overridden by the :set option&quot; do
     setup do
-      @output = Whenever.cron :set =&gt; 'cron_log=otherlog.log', :string =&gt; \
+      @output = Whenever.cron :set =&gt; 'output=otherlog.log', :string =&gt; \
       &lt;&lt;-file
-        set :cron_log, 'logfile.log'
+        set :output, 'logfile.log'
         every 2.hours do
           command &quot;blahblah&quot;
         end
@@ -84,21 +150,158 @@ class OutputCommandTest &lt; Test::Unit::TestCase
     end
   end
   
-  context &quot;An every statement with two commands in it&quot; do
+  context &quot;A command when the error and standard output is set&quot; do
     setup do
       @output = Whenever.cron \
       &lt;&lt;-file
-        every 1.hour do
-          command &quot;first&quot;
-          command &quot;second&quot;
+        set :output, {:error =&gt; 'dev_err', :standard =&gt; 'dev_null' }
+        every 2.hours do
+          command &quot;blahblah&quot;
         end
       file
     end
 
-    should &quot;output both commands&quot; do
-      assert_match &quot;0 * * * * first&quot;, @output
-      assert_match &quot;0 * * * * second&quot;, @output
+    should &quot;output the command without the redirection syntax appended&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; dev_null 2&gt; dev_err$/, @output
     end
   end
+
+  context &quot;A command when error output is set&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        set :output, {:error =&gt; 'dev_null'}
+        every 2.hours do
+          command &quot;blahblah&quot;
+        end
+      file
+    end
+
+    should &quot;output the command without the standard errror syntax appended&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah 2&gt; dev_null$/, @output
+    end
+  end
+  
+  context &quot;A command when the standard output is set&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        set :output, {:standard =&gt; 'dev_out'}
+        every 2.hours do
+          command &quot;blahblah&quot;
+        end
+      file
+    end
+
+    should &quot;output the command with standard output syntax appended&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; dev_out$/, @output
+    end
+  end
+
+  context &quot;A command when error output is set by the command&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:error =&gt; 'dev_err'}
+        end
+      file
+    end
+
+    should &quot;output the command without the log syntax appended&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah 2&gt; dev_err$/, @output
+    end
+  end
+  
+  context &quot;A command when standard output is set by the command&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:standard =&gt; 'dev_out'}
+        end
+      file
+    end
+
+    should &quot;output the command without the log syntax appended&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; dev_out$/, @output
+    end
+  end
+
+  context &quot;A command when standard output is set to nil&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:standard =&gt; nil}
+        end
+      file
+    end
+
+    should &quot;output the command with stdout directed to /dev/null&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; \/dev\/null$/, @output
+    end
+  end
+
+  context &quot;A command when standard error is set to nil&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:error =&gt; nil}
+        end
+      file
+    end
+
+    should &quot;output the command with stderr directed to /dev/null&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah 2&gt; \/dev\/null$/, @output
+    end
+  end
+
+  context &quot;A command when standard output and standard error is set to nil&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:error =&gt; nil, :standard =&gt; nil}
+        end
+      file
+    end
+
+    should &quot;output the command with stderr directed to /dev/null&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; \/dev\/null 2&gt;&amp;1$/, @output
+    end
+  end
+
+  context &quot;A command when standard output is set and standard error is set to nil&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:error =&gt; nil, :standard =&gt; 'my.log'}
+        end
+      file
+    end
+
+    should &quot;output the command with stderr directed to /dev/null&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; my.log 2&gt; \/dev\/null$/, @output
+    end
+  end
+
+  context &quot;A command when standard output is nil and standard error is set&quot; do
+    setup do
+      @output = Whenever.cron \
+      &lt;&lt;-file
+        every 2.hours do
+          command &quot;blahblah&quot;, :output =&gt; {:error =&gt; 'my_error.log', :standard =&gt; nil}
+        end
+      file
+    end
+
+    should &quot;output the command with stderr directed to /dev/null&quot; do
+      assert_match /^.+ .+ .+ .+ blahblah &gt;&gt; \/dev\/null 2&gt; my_error.log$/, @output
+    end
+  end
+
   
 end
\ No newline at end of file</diff>
      <filename>test/output_command_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>53b92aa84ba0abbd642ca0a1cdf48ec3fb3f2b2f</id>
    </parent>
  </parents>
  <author>
    <name>Peer Allan</name>
    <email>peer@canadadrugs.com</email>
  </author>
  <url>http://github.com/javan/whenever/commit/be38dd1139a40c2f08d2d40ec20a7c54004fb154</url>
  <id>be38dd1139a40c2f08d2d40ec20a7c54004fb154</id>
  <committed-date>2009-10-17T15:49:16-07:00</committed-date>
  <authored-date>2009-09-18T07:50:16-07:00</authored-date>
  <message>Added output redirection support

* replaced cron_log option with output
  * setting output to nil explicitly redirects to /dev/null
  * updated Readme and wheneverize template with examples</message>
  <tree>a9d2353981e37cb192bd2c6f6895704098659d1d</tree>
  <committer>
    <name>Javan Makhmali</name>
    <email>javan@javan.us</email>
  </committer>
</commit>
