Feature Requests: Browse | Submit New | Admin

[#20768] option for thread output prefix

Date:
2008-06-21 21:04
Priority:
3
Submitted By:
Daniel Kionka (dkionka)
Assigned To:
John Barnette (jbarnette)
Category:
vlad
State:
Open
Summary:
option for thread output prefix

Detailed description
Since the output of so many threads gets intermixed, it would be great to have the option of prefixing each line with
some identification.  Then you could grep the output file later to isolate one of the hosts.

I would make it 3 values for the option:
- nil/false disables
- true uses target_host
- String is a user-defined prefix

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-06-01 15:23
Sender: Aaron Suggs

Sorry Ryan,

There's no checkbox or file attacher dialog for any tickets in
either the "feature requests" section. But I can attach
files in the patches section. So I added the patch here:

http://rubyforge.org/tracker/index.php?func=detail&aid=26088&
amp;group_id=4213&atid=16260

Thanks!

-Aaron
Date: 2009-05-29 21:32
Sender: Ryan Davis

that's just gonna be munged.

to attach a file, do the regular "choose file" button
below, but also make sure you check the stupid checkbox. next
to it. lame.
Date: 2009-05-29 18:45
Sender: Aaron Suggs

Hrm, I don't see how to attach a file to this Feature Request...here's
the patch:

From 7b6522df086f5e1c28d585483b9c74eb1fa660e5 Mon Sep 17 00:00:00
2001
From: Aaron Suggs <aaron@ktheory.com>
Date: Fri, 29 May 2009 10:49:45 -0400
Subject: [PATCH] Added setting to prefix output with target_host

Prefixing is disabled by default. To enable output prefixes,
add the
following to config/deploy.rb:

  set :prefix_output, true

Each line of output (stdout and stderr) will be prefixed
target_host

You can also set :prefix_output to a custom string or block.
E.g.:

  set :prefix_ouput, :per_thread do
    "On #{Thread.current[:task].target_host} at #{Time.now}:
"
  end
---
 lib/rake_remote_task.rb       |   13 ++++++++++++-
 test/test_rake_remote_task.rb |   16 ++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/lib/rake_remote_task.rb b/lib/rake_remote_task.rb
index a77077b..8a6436d 100644
--- a/lib/rake_remote_task.rb
+++ b/lib/rake_remote_task.rb
@@ -223,6 +223,16 @@ class Rake::RemoteTask < Rake::Task
         end
 
         data = stream.readpartial(1024)
+
+        # Add the prefix to each line
+        if (prefix = prefix_output)
+          # default to the target hostname
+          prefix = "#{target_host}: " if prefix ==
true
+
+          # don't prefix sudo prompts
+          data.gsub!(/^/, prefix) unless stream == err and data
=~ sudo_prompt
+        end
+
         out_stream[stream].write data
 
         if stream == err and data =~ sudo_prompt then
@@ -455,7 +465,8 @@ class Rake::RemoteTask < Rake::Task
                :sudo_cmd,           "sudo",
                :sudo_flags,         ['-p Password:'],
                :sudo_prompt,        /^Password:/,
-               :umask,              '02')
+               :umask,              '02',
+               :prefix_output,      false)
 
     set(:current_release)    { File.join(releases_path, releases[-1])
}
     set(:latest_release)     { deploy_timestamped ?release_path:
current_release }
diff --git a/test/test_rake_remote_task.rb
b/test/test_rake_remote_task.rb
index 0a567f2..7bb4400 100644
--- a/test/test_rake_remote_task.rb
+++ b/test/test_rake_remote_task.rb
@@ -117,6 +117,22 @@ class TestRakeRemoteTask < VladTestCase
     assert_equal 1, @task.commands.size
   end
 
+  def test_run_with_prefix_output
+    util_setup_task
+    @task.output << "file1\nfile2\n"
+    @task.target_host = "app.example.com"
+    result = nil
+
+    set :prefix_output, true
+
+    out, err = util_capture do
+      result = @task.run("ls")
+    end
+
+    assert_equal "app.example.com: file1\napp.example.com:
file2\n", result
+    assert_equal "app.example.com: file1\napp.example.com:
file2\n", out.read
+  end
+
   def test_run_sudo
     util_setup_task
     @task.output << "file1\nfile2\n"
-- 
1.6.1.1

Date: 2009-05-29 18:43
Sender: Aaron Suggs

I'd like this option too. Attached is a patch to do this.

Prefixing is disabled by default. To enable output prefixes,
add the
following to config/deploy.rb:

  set :prefix_output, true

Each line of output (stdout and stderr) will be prefixed
target_host

You can also set :prefix_output to a custom string or block.
E.g.:

  set :prefix_ouput, :per_thread do
    "On #{Thread.current[:task].target_host} at #{Time.now}:
"
  end

I also posted the patch to github:
http://github.com/ktheory/vlad/commit/7b6522df086f5e1c28d585483b9
c74eb1fa660e5
Date: 2009-03-05 22:34
Sender: Ryan Davis

I don't really have any desire to do this, but patches are
welcome.

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
assigned_tozenspider2009-07-28 22:23zenspider