Feature #163

avatar

Formattable output prefix.

Added by Erich Heine 117 days ago. Updated 2 days ago.

Status:New Start:05/14/2010
Priority:Normal Due date:
Assigned to:avatarJeff Forcier % Done:

0%

Category:UI
Target version:1.1

Description

It seems that the output prefix should be a bit more flexible than it currently is. The current format is:

[hoststring] Message

This should be flexible. An ideal situation would be to use python’s built-in template strings. (or to be very forward thinking format strings, but those require 2.6). The template can be put in evn.output.prefix or similar. Using the templates it is easy to just define output format based on exposed variables.

These could include:

  • hostname
  • hoststring
  • comand output signifier [1][2]
  • time [1]
  • other stuff

It could also include color code formatting.

[1] some variables will need to have a helper variable, e.g. strftime format for time [2] output signifier could be something simple like a ** making the output something like:

[hostname] Log msg
[hostname] ** output from cmd

An example format string (with helpers) could look like:

env.output.prefix = "[${hostname} - ${time}] ${cmd_sig}"
env.output.timeformat = "H:M"
env.output.cmd_sig = "**"

resulting in:

[www1.foo.com - 17:05] Executing hostname
[www1.foo.com - 17:05] ** www1.foo.com

Related issues

related to Feature #57 Support full logging to file Assigned 09/06/2009
related to Feature #7 Improved prompt detection and passthrough Done 07/20/2009
related to Bug #164 puts show_prefix New 05/19/2010

History

Updated by Erich Heine 117 days ago

avatar

OK, so formatting fail… it should read:

These could include:

  • hostname
  • hoststring
  • command output signifier [1][2]
  • time [1]
  • other stuff

Updated by Jeff Forcier 117 days ago

avatar

Tweaked formatting a bit for you. Thanks for making the ticket.

I agree that the forward compatible string formatting would be best but I don’t want to rely on 2.6 yet so that’s unfortunately out.

Amusingly a translated format string brings us back to the older magical string interpolation, but since it’s required for dynamic stuff like this and is limited to a single spot of the code, may not be so bad.

An alternative is a call chain, an array of callbacks, e.g. it might start out as env.prefix = [lambda: env.host_string] and one could then, in their fabfile’s module level, do env.prefix.append(lambda: datetime.now.strftime("whatevs")). This feels somewhat more Pythonic to me at the expense of losing some control over the exact prefix string format.

Updated by Erich Heine 116 days ago

avatar

Nice! I like it anytime callbacks can be incorporated anywhere. The thing we are discussing at this point tho is an “almost but not quite” version of python’s logging module. Perhaps that should be looked at for either inspiration or instead of a one-off. Refreshing myself on the module, I notice there are a few things that could help in other places too. There are handlers and formatters, and it supports the notion of levels, so theoretically this could do everything fabric already aims to do regarding output. The biggest problem would be prompting, but if the chain of events goes (remote process output)–>(paramiko.stdout/stderr) –> (prompt/expect handling) –> logger it may not be a big deal.

Anyway, some food for thought for the morning.

Updated by Jeff Forcier 116 days ago

avatar
  • Category set to UI
  • Assigned to set to Jeff Forcier
  • Target version set to 0.9.2

Good point. We do have tickets open that refer to using the logging module, and I think some of them did mention using it for stdout as well as to-file logging. Will add them as related items in case that has any bearing on this specific issue (I haven’t really played with the logging module much, but given how logs are, I do expect it’ll have prefix options…)

Updated by Jeff Forcier 79 days ago

avatar

Keep in mind that a fully empty prefix should also be easy to effect, though offhand that should simply be an empty-string prefix setting, so not a big deal.

For example, now that #7 is basically done, fully interactive stuff is going to want prefixing turned off completely lest it look terribly ugly or even broken.

Updated by Jeff Forcier 3 days ago

avatar
  • Target version changed from 0.9.2 to 0.9.3

Updated by Jeff Forcier 2 days ago

avatar
  • Target version changed from 0.9.3 to 1.0

Updated by Jeff Forcier 2 days ago

avatar
  • Target version changed from 1.0 to 1.1

Also available in: Atom