Skip to content
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

Display executed commands via Verbose Logging #111

Merged
merged 8 commits into from
Nov 10, 2017

Conversation

grayside
Copy link
Contributor

@grayside grayside commented Oct 31, 2017

Finally getting back to the learnification.

This is still in-progress but wanted to get an approach confirmation before continuing.

3__thanks_for_flying_vim__zsh_

Fixes #5

@grayside grayside requested review from tekante and febbraro October 31, 2017 18:46
@grayside grayside changed the title Display commands executed by StreamCommand and rig dashboard. [WIP] Display executed commands via Verbose Logging [WIP] Oct 31, 2017
@febbraro
Copy link
Member

Maybe we should use util.Run for everything instead of exec.Command and then we can just create the command to run? like maybe util.Run returns an exec.Cmd so you can still choose to Run or CombineOutput or whatever? I realize we dont always handle Cmds in a consistent way, but seems more clear/simple than wrapping every exec.Command call

@grayside
Copy link
Contributor Author

The problem there is if we output the log when we create the command, that could be out of sequence when we actually execute it. Certainly wrapping the exec.Command factory is part of the strategy in #97 so I don't object on that point.

Would it make sense to extend exec.Cmd into our own struct and shadow Run et al with the verbose logging?

@febbraro
Copy link
Member

Shadowing might be good, sometimes we don't call Run() directly though, but call CombinedOutput() or Output(), I wonder if shadowing Run() would get our method called, or the base struct?

@grayside
Copy link
Contributor Author

grayside commented Nov 1, 2017

To do this at exec time, I assume we need to shadow each unless the API internals use a common exec call we can shadow.

Adam Ross added 2 commits November 9, 2017 16:41
…ogging

* origin/develop:
  Fixed bug in libnss-resolver DNS resolution (#116)
  Added rpm to build, well, rpms
  Transitioned to different go base to try to head off problems with dynamically linked go binaries
  tweaking some build flags
  tweaking CGO
  messing with ldflags
  tweaked goreleaser config
  fixed BaseCommand initialization in delegated commands (#114)
  Addeed .DS_Store to .gitignore
  Linux DNS install (#112)
@grayside
Copy link
Contributor Author

Moved command output to yellow for better visibility. Shifted to more of an object wrapper model. Stopped implementation for approach review.


// Run runs a command via exec.Run() without modification or output of the underlying command.
func (x Executor) Run() error {
return x.cmd.Run()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to log all commands that are run? Or only commands that force/stream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably all commands, but I wanted to lay out the initial API for it more flexibly so the refactoring can go either way.

@febbraro
Copy link
Member

I like how this is looking a lot better. The code that needs to run commands look really no different and is still pretty easy to read, and the Executor looks pretty simple.

// StreamCommand sets up the output streams (and colors) to stream command output if verbose is configured
func StreamCommand(cmd *exec.Cmd) error {
return RunCommand(cmd, false)
return Executor{cmd}.Execute(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, we could make this and ForceStreamCommand even easier to read on the caller side if we just take the command and args here instead of the exec.Cmd and call exec.Command just like the Executor.Execute

@grayside
Copy link
Contributor Author

Too much?

3__root_bbefb61ec982__var_www_northwell-d8__zsh_

@grayside
Copy link
Contributor Author

Note that in the example above, we see that our use of machine.GetData() could maybe do some static caching. Likely a nice little performance optimization.

@grayside grayside changed the title Display executed commands via Verbose Logging [WIP] Display executed commands via Verbose Logging Nov 10, 2017
@febbraro febbraro merged commit 80aaf4e into develop Nov 10, 2017
@febbraro febbraro deleted the learning/command-logging branch November 10, 2017 23:27
grayside pushed a commit that referenced this pull request Nov 11, 2017
* origin/develop:
  Display executed commands via Verbose Logging (#111)
  Better cross platform builds (#118)
  Fixing Outrigger Dashboard on Linux (#117)
  Fixed bug in libnss-resolver DNS resolution (#116)
  Added rpm to build, well, rpms
  Transitioned to different go base to try to head off problems with dynamically linked go binaries
  tweaking some build flags
  tweaking CGO
  messing with ldflags
  tweaked goreleaser config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants