-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce explicit command logging methods and deprecate stdout / stderr Command attrs #257
Introduce explicit command logging methods and deprecate stdout / stderr Command attrs #257
Conversation
@robd the two methods I'd be thrilled to see this merged, it's a drastic clean up, and I like the deprecation solution you've proposed, let's build it. |
@robd This looks very nice. 👍 to merge. My only nitpick would be I think the meta-programming you've used to define methods in Edit: I realize this is not ready to merge yet, but I like the direction it is going! |
OK great. Re the I think it would be OK to just delete the new First of all I want to add support for showing deprecation warnings safely as a separate PR. I propose to add this as a separate logger to the main formatter for the following reasons:
I will rework the existing deprecation call we have and update the docs. |
Try to expose when changes may break a ‘typical’ custom formatter which has been implemented based on the Pretty formatter
No longer rely on state in Command for determining log message type or std stream data
6ad3871
to
36b7c6a
Compare
423a022
to
747711e
Compare
Remove unused clear_stdout_lines / clear_stderr_lines methods which were never released
747711e
to
fb19c38
Compare
OK, I have incorporated the feedback, deprecated the old From my perspective this is ready to merge. @mattbrictson Do you want me to look at integrating this into I guess we will want to override Let me know if I can help. |
@robd if you want to take a stab at a PR for airbrussh, that would be fantastic. Ideally I would like airbrussh to continue working with any version of sshkit >= 1.6.1. But if the conditional code to do that is too complicated (i.e. worse than |
@mattbrictson No probs - I'll see what I can do :) |
The log_command_start, log_command_data and log_command_exit methods will be supported when PR257 is merged - capistrano/sshkit#257
The necessary Airbrussh changes are in mattbrictson/airbrussh#17. @leehambley I wondered, would you be up for merging the Airbrussh formatter into SSHKit? This would dramatically ease maintenance of Airbrussh, because at the moment trying to support various versions of SSHKit as the formatter API changes requires quite a bit of care and effort. I don't propose to do this right now, because I want to get back to finishing up support for interactive sudo, but I wanted to find out your thoughts on this.. |
I'd be more than happy to make it the default formatter, but I wouldn't want to put @mattbrictson in a position where his work is under appreciated, and he's insufficiently credited for it. Open to anything, give me a break though, I'm travelling a lot this week, and next week when I'm back we're launching a new company >_<, but yeah - would love to if @mattbrictson is up for it. @mattbrictson actually heads-up I'm in SFO the next 4 days for IO if you feel like letting me buy you a beer. |
Introduce explicit command logging methods and deprecate stdout / stderr Command attrs
The log_command_start, log_command_data and log_command_exit methods are supported since capistrano/sshkit#257
@leehambley OK great. I don't think the Airbrussh merge is urgent - we can pick this up at some later stage once things have calmed down at your end. Have a good IO and good luck with the launch. |
## 1.8.1 * Change license to MIT, thanks to all the patient contributors who gave their permissions. ## 1.8.0 * add SSHKit::Backend::ConnectionPool#close_connections [PR #285](capistrano/sshkit#285) @akm * Clean up rubocop lint warnings [PR #275](capistrano/sshkit#275) @cshaffer * Prepend unused parameter names with an underscore * Prefer “safe assignment in condition” * Disambiguate regexp literals with parens * Prefer `sprintf` over `String#%` * No longer shadow `caller_line` variable in `DeprecationLogger` * Rescue `StandardError` instead of `Exception` * Remove useless `private` access modifier in `TestAbstract` * Disambiguate block operator with parens * Disambiguate between grouped expression and method params * Remove assertion in `TestHost#test_assert_hosts_compare_equal` that compares something with itself * Export environment variables and execute command in a subshell. [PR #273](capistrano/sshkit#273) @kuon * Introduce `log_command_start`, `log_command_data`, `log_command_exit` methods on `Formatter` [PR #257](capistrano/sshkit#257) @robd * Deprecate `@stdout` and `@stderr` accessors on `Command` * Add support for deprecation logging options. [README](README.md#deprecation-warnings), [PR #258](capistrano/sshkit#258) @robd * Quote environment variable values. [PR #250](capistrano/sshkit#250) @Sinjo - Chris Sinjakli * Simplified formatter hierarchy. [PR #248](capistrano/sshkit#248) @robd * `SimpleText` formatter now extends `Pretty`, rather than duplicating. * Hide ANSI color escape sequences when outputting to a file. [README](README.md#output-colors), [Issue #245](capistrano/sshkit#245), [PR #246](capistrano/sshkit#246) @robd * Now only color the output if it is associated with a tty, or the `SSHKIT_COLOR` environment variable is set. * Removed broken support for assigning an `IO` to the `output` config option. [Issue #243](capistrano/sshkit#243), [PR #244](capistrano/sshkit#244) @robd * Use `SSHKit.config.output = SSHKit::Formatter::SimpleText.new($stdin)` instead * Added support for `:interaction_handler` option on commands. [PR #234](capistrano/sshkit#234), [PR #242](capistrano/sshkit#242) @robd * Removed partially supported `TRACE` log level. [2aa7890](capistrano/sshkit@2aa7890) @robd * Add support for the `:strip` option to the `capture` method and strip by default on the `Local` backend. [PR #239](capistrano/sshkit#239), [PR #249](capistrano/sshkit#249) @robd * The `Local` backend now strips by default to be consistent with the `Netssh` one. * This reverses change [7d15a9a](capistrano/sshkit@7d15a9a) to the `Local` capture API to remove stripping by default. * If you require the raw, unstripped output, pass the `strip: false` option: `capture(:ls, strip: false)` * Simplified backend hierarchy. [PR #235](capistrano/sshkit#235), [PR #237](capistrano/sshkit#237) @robd * Moved duplicate implementations of `make`, `rake`, `test`, `capture`, `background` on to `Abstract` backend. * Backend implementations now only need to implement `execute_command`, `upload!` and `download!` * Removed `Printer` from backend hierarchy for `Local` and `Netssh` backends (they now just extend `Abstract`) * Removed unused `Net::SSH:LogLevelShim` * Removed dependency on the `colorize` gem. SSHKit now implements its own ANSI color logic, with no external dependencies. Note that SSHKit now only supports the `:bold` or plain modes. Other modes will be gracefully ignored. [#263](capistrano/sshkit#263) * New API for setting the formatter: `use_format`. This differs from `format=` in that it accepts options or arguments that will be passed to the formatter's constructor. The `format=` syntax will be deprecated in a future release. [#295](capistrano/sshkit#295) * SSHKit now immediately raises a `NameError` if you try to set a formatter that does not exist. [#295](capistrano/sshkit#295)
## 1.8.1 * Change license to MIT, thanks to all the patient contributors who gave their permissions. ## 1.8.0 * add SSHKit::Backend::ConnectionPool#close_connections [PR #285](capistrano/sshkit#285) @akm * Clean up rubocop lint warnings [PR #275](capistrano/sshkit#275) @cshaffer * Prepend unused parameter names with an underscore * Prefer “safe assignment in condition” * Disambiguate regexp literals with parens * Prefer `sprintf` over `String#%` * No longer shadow `caller_line` variable in `DeprecationLogger` * Rescue `StandardError` instead of `Exception` * Remove useless `private` access modifier in `TestAbstract` * Disambiguate block operator with parens * Disambiguate between grouped expression and method params * Remove assertion in `TestHost#test_assert_hosts_compare_equal` that compares something with itself * Export environment variables and execute command in a subshell. [PR #273](capistrano/sshkit#273) @kuon * Introduce `log_command_start`, `log_command_data`, `log_command_exit` methods on `Formatter` [PR #257](capistrano/sshkit#257) @robd * Deprecate `@stdout` and `@stderr` accessors on `Command` * Add support for deprecation logging options. [README](README.md#deprecation-warnings), [PR #258](capistrano/sshkit#258) @robd * Quote environment variable values. [PR #250](capistrano/sshkit#250) @Sinjo - Chris Sinjakli * Simplified formatter hierarchy. [PR #248](capistrano/sshkit#248) @robd * `SimpleText` formatter now extends `Pretty`, rather than duplicating. * Hide ANSI color escape sequences when outputting to a file. [README](README.md#output-colors), [Issue #245](capistrano/sshkit#245), [PR #246](capistrano/sshkit#246) @robd * Now only color the output if it is associated with a tty, or the `SSHKIT_COLOR` environment variable is set. * Removed broken support for assigning an `IO` to the `output` config option. [Issue #243](capistrano/sshkit#243), [PR #244](capistrano/sshkit#244) @robd * Use `SSHKit.config.output = SSHKit::Formatter::SimpleText.new($stdin)` instead * Added support for `:interaction_handler` option on commands. [PR #234](capistrano/sshkit#234), [PR #242](capistrano/sshkit#242) @robd * Removed partially supported `TRACE` log level. [2aa7890](capistrano/sshkit@2aa7890) @robd * Add support for the `:strip` option to the `capture` method and strip by default on the `Local` backend. [PR #239](capistrano/sshkit#239), [PR #249](capistrano/sshkit#249) @robd * The `Local` backend now strips by default to be consistent with the `Netssh` one. * This reverses change [7d15a9a](capistrano/sshkit@7d15a9a) to the `Local` capture API to remove stripping by default. * If you require the raw, unstripped output, pass the `strip: false` option: `capture(:ls, strip: false)` * Simplified backend hierarchy. [PR #235](capistrano/sshkit#235), [PR #237](capistrano/sshkit#237) @robd * Moved duplicate implementations of `make`, `rake`, `test`, `capture`, `background` on to `Abstract` backend. * Backend implementations now only need to implement `execute_command`, `upload!` and `download!` * Removed `Printer` from backend hierarchy for `Local` and `Netssh` backends (they now just extend `Abstract`) * Removed unused `Net::SSH:LogLevelShim` * Removed dependency on the `colorize` gem. SSHKit now implements its own ANSI color logic, with no external dependencies. Note that SSHKit now only supports the `:bold` or plain modes. Other modes will be gracefully ignored. [#263](capistrano/sshkit#263) * New API for setting the formatter: `use_format`. This differs from `format=` in that it accepts options or arguments that will be passed to the formatter's constructor. The `format=` syntax will be deprecated in a future release. [#295](capistrano/sshkit#295) * SSHKit now immediately raises a `NameError` if you try to set a formatter that does not exist. [#295](capistrano/sshkit#295)
At the moment, one of the hardest bits of code to understand, and the source of some historical bugs, is the
@stdout
,@stderr
attributes on command. These are used as a temporary buffer of the latest unconsumed output lines by the formatters. The backends append to the buffer (netssh, local) via the on_stdout and on_stderr methods, and then the pretty formatter clears the buffers via the clear_stdout_lines and clear_stderr_lines methods.As well as being hard to understand, it makes integrating with SSHKit harder. For example, Airbrussh has to dup the
Command
in order to make sure that stdout/stderr are not cleared by the pretty formatter.In order to fix this, I propose to widen the
Formatter
API and include 3 specific methods (log_command_start
,log_command_data
,log_command_exit
) for logging the different command states rather than switching on the internal state inCommand
.The other state on
Command
(ie :started_at, :started, :exit_status, :full_stdout, :full_stderr) is less confusing because at least this state is all being set by the backends, and simply read by the formatters (rather than mutated). I propose to leave these for the moment.As part of this, I'd like to deprecate
@stdout
and@stderr
onCommand
to explain the changes to people who use the stdout / stderr accessors. (I deleted these previously, but I will reinstate them with deprecation warnings). In order to do this, I am intending to write a de-duplicating deprecator and introduce a new config option -SSHKit.config.deprecation_output
which takes the same sort of object as the normal output (ie one which implements<<
). By default, I propose to log deprecation directly tostderr
. This means deprecation errors will show up for people using formatters which hide normal warnings (egDot
orBlackHole
). Deprecation warnings can easily be disabled:@mattbrictson I discussed I had some ideas for this a while ago. If you don't mind, can you look at the new formatter methods and see what you think?
@leehambley Would value your thoughts on this as always.