buffering output per line

45 views
Skip to first unread message

Stephen Haberman

unread,
Oct 27, 2006, 1:49:56 PM10/27/06
to capis...@googlegroups.com
Hi,

I have not been using capistrano for a whole lot just yet, but for
executing the few remote commands I've been doing, I've found buffering
the return output per line to be a lot easier to read:

# Buffer capistrano output per line
Capistrano::Actor.default_io_proc = Proc.new do |ch, stream, out|
ch[stream] ||= ''
ch[stream] << out
if out[-1..-1] == "\n"
level = stream == :err ? :important : :info
ch[:actor].logger.send(level, ch[stream], "#{stream} :: #{ch[:host]}")
ch[stream] = ''
end
end

I must admit its been a few weeks since I wrote this, but as I recall it
turned the output I was seeing from:

out :: host1 Restarting daemon
out :: host1 [OK]
out :: host1 ...
out :: host2 Restarting daemon
out :: host2 [OK]
out :: host2 ...

To just:

out :: host1 Restarting daemon [OK]
out :: host2 Restarting daemon [OK]

I would almost suggest this as a patch, but just because its desirable
for my situation, I don't know if its desirable for all situations.

- Stephen

Jamis Buck

unread,
Nov 1, 2006, 12:50:12 PM11/1/06
to capis...@googlegroups.com
Stephen,

I've considered this, but I don't want this behavior in general. For
instance, consider the long-running process that emits some progress
indicator character, like a '.', each time some increment of the
operation finishes. A newline may not be emitted for many minutes,
but you'd like to see some progress being made.

For an action that you know will not behave like that, though, it
might be a nice option to specify that you want line buffering.
Perhaps as an option to run:

run "some command", :buffer => true do |ch, stream, out|
...
end

Thoughts?

- Jamis

> --~--~---------~--~----~------------~-------~--~----~
> To unsubscribe from this group, send email to capistrano-
> unsub...@googlegroups.com
> For more options, visit this group at http://groups.google.com/
> group/capistrano
> -~----------~----~----~----~------~----~------~--~---
>

Stephen Haberman

unread,
Nov 1, 2006, 4:41:21 PM11/1/06
to capis...@googlegroups.com
On Wed, 1 Nov 2006 10:50:12 -0700
Jamis Buck <ja...@37signals.com> wrote:

> I've considered this, but I don't want this behavior in general. For
> instance, consider the long-running process that emits some progress
> indicator character, like a '.', each time some increment of the
> operation finishes. A newline may not be emitted for many minutes,
> but you'd like to see some progress being made.

Good point. That's the sort of use case I was thinking of but could not
articulate.

> For an action that you know will not behave like that, though, it
> might be a nice option to specify that you want line buffering.
> Perhaps as an option to run:
>
> run "some command", :buffer => true do |ch, stream, out|
> ...
> end

I like that. But instead of :buffer, perhaps :per_line_output. Or
something like that.

I've attached a patch--but haven't actually tried it yet. Later today
I'll likely be using capistrano to deploy some stuff and will try it out
then.

- Stephen

capistrano-per_line_output.diff
Reply all
Reply to author
Forward
0 new messages