Skip to content

Commit

Permalink
Remove docs about assigning an IO to SSHKit.config.output (see capist…
Browse files Browse the repository at this point in the history
  • Loading branch information
robd committed May 6, 2015
1 parent e4e0a1a commit 6c40d95
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ appear at the top.

* Add your entries below here, remember to credit yourself however you want
to be credited!
* Removed broken support for assigning an `IO` to the `output` config option (See #243). @robd
* Use `SSHKit.config.output = SSHKit::Formatter::SimpleText.new($stdin)` instead
* Added support for :interaction_handler option on commands. @robd
* Removed partially supported 'trace' log level. @robd
* No longer strip whitespace or newlines in `capture` method on Netssh backend. @robd
Expand Down
30 changes: 24 additions & 6 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,41 @@ on hosts do
end
```

## Redirect all output to `/dev/null`
## Change the output formatter

```ruby
SSHKit.config.output = File.open('/dev/null')
# The default format is pretty, which outputs colored text
SSHKit.config.format = :pretty

# Text with no coloring
SSHKit.config.format = :simpletext

# Red / Green dots for each completed step
SSHKit.config.format = :dot

# No output
SSHKit.config.format = :blackhole
```

## Implement a dirt-simple formatter class

```ruby
class MyFormatter < SSHKit::Formatter::Abstract
def write(obj)
case obj.is_a? SSHKit::Command
# Do something here, see the SSHKit::Command documentation
module SSHKit
module Formatter
class MyFormatter < SSHKit::Formatter::Abstract
def write(obj)
case obj.is_a? SSHKit::Command
# Do something here, see the SSHKit::Command documentation
end
end
end
end
end

# If your formatter is defined in the SSHKit::Formatter module configure with the format option:
SSHKit.config.format = :myformatter

# Or configure the output directly
SSHKit.config.output = MyFormatter.new($stdout)
SSHKit.config.output = MyFormatter.new(SSHKit.config.output)
SSHKit.config.output = MyFormatter.new(File.open('log/deploy.log', 'wb'))
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,32 @@ By default, the output format is set to `:pretty`:
SSHKit.config.format = :pretty
```

However, if you prefer minimal output, `:dot` format will simply output red or green dots based on the success or failure of operations.
However, if you prefer non colored text you can use the `:simpletext` formatter. If you want minimal output,
there is also a `:dot` formatter which will simply output red or green dots based on the success or failure of commands.
There is also a `:blackhole` formatter which does not output anything.

To output directly to $stdout without any formatting, you can use:
By default, formatters log to `$stdout`, but they can be constructed with any `IO`:

```ruby
SSHKit.config.output = $stdout
# Output to a StringIO:
out = StringIO.new
SSHKit.config.output = SSHKit::Formatter::Pretty.new(out)
# Do something with out.string

# Or output to a file:
SSHKit.config.output = SSHKit::Formatter::SimpleText.new(File.open('log/deploy.log', 'wb'))
```

#### Custom formatters

Want custom output formatting? Here's what you have to do:

1. Write a new formatter class in the `SSHKit::Formatter` namespace. As an example, check out the default [pretty](https://github.com/capistrano/sshkit/blob/master/lib/sshkit/formatters/pretty.rb) formatter.
1. Set the output format as described above. E.g. if your new formatter is called `Foobar`:

SSHKit.config.format = :foobar
1. Write a new formatter class in the `SSHKit::Formatter` module. As an example, check out the default [pretty](https://github.com/capistrano/sshkit/blob/master/lib/sshkit/formatters/pretty.rb) formatter.
1. Set the output format as described above. E.g. if your new formatter is called `FooBar`:

```ruby
SSHKit.config.format = :foobar
```

## Output Verbosity

Expand Down

0 comments on commit 6c40d95

Please sign in to comment.