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

Refinement of new logging API usage. #124

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (cmd *BaseCommand) Success(message string) error {
util.NotifySuccess(cmd.context, message)
}

// If there is an active spinner wrap it up.
// If there is an active spinner wrap it up. This is not placed before the logging above so commands can rely on
// cmd.Success to set the last spinner status in lieu of an extraneous log entry.
cmd.out.NoSpin()

return nil
Expand Down
6 changes: 5 additions & 1 deletion commands/data_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (cmd *DataBackup) Run(c *cli.Context) error {
return cmd.Failure("Backup failed", "COMMAND-ERROR", 13)
}

cmd.out.Info("Backup complete: %s", backupFile)
cmd.out.Info("Data backup saved to %s", backupFile)
// Our final success message provides details on where to find the backup file.
// The success notifcation is kept simple by not passing back the filepath.
cmd.out.NoSpin()

return cmd.Success("Data Backup completed")
}
3 changes: 1 addition & 2 deletions commands/data_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ func (cmd *DataRestore) Run(c *cli.Context) error {
return cmd.Failure("Data restore failed", "COMMAND-ERROR", 13)
}

cmd.out.Info("Data restore complete")
return cmd.Success("Data Restore was successful")
return cmd.Success("Data Restore completed")
}
5 changes: 2 additions & 3 deletions commands/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func (cmd *DNS) Commands() []cli.Command {

// Run executes the `rig dns` command
func (cmd *DNS) Run(c *cli.Context) error {
cmd.out.Info("Configuring DNS")

if !util.SupportsNativeDocker() && !cmd.machine.IsRunning() {
return cmd.Failure(fmt.Sprintf("Machine '%s' is not running.", cmd.machine.Name), "MACHINE-STOPPED", 12)
}
Expand All @@ -51,6 +49,7 @@ func (cmd *DNS) Run(c *cli.Context) error {
if !util.SupportsNativeDocker() {
cmd.ConfigureRoutes(cmd.machine)
}

return cmd.Success("DNS Services have been started")
}

Expand Down Expand Up @@ -153,7 +152,7 @@ func (cmd *DNS) StartDNS(machine Machine, nameservers string) error {
args = append(args, "--nameserver="+server)
}

util.ForceStreamCommand("docker", args...)
util.StreamCommand("docker", args...)
// Configure the resolvers based on platform
var resolverReturn error
if util.IsMac() {
Expand Down
4 changes: 2 additions & 2 deletions commands/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (cmd *Kill) Run(c *cli.Context) error {
return err
}

cmd.out.Channel.Info.Printf("Killing machine '%s'", cmd.machine.Name)
cmd.out.Info("Killing machine '%s'", cmd.machine.Name)
util.StreamCommand("docker-machine", "kill", cmd.machine.Name)

// Ensure the underlying virtualization has stopped
Expand All @@ -53,7 +53,7 @@ func (cmd *Kill) Run(c *cli.Context) error {
case util.Xhyve:
cmd.out.Warning("Add equivalent xhyve kill command.")
default:
cmd.out.Channel.Warning.Printf("Driver not recognized: %s\n", driver)
cmd.out.Warning("Driver not recognized: %s\n", driver)
}

return cmd.Success(fmt.Sprintf("Machine '%s' killed", cmd.machine.Name))
Expand Down
10 changes: 5 additions & 5 deletions commands/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Machine struct {

// Create will generate a new Docker Machine configured according to user specification
func (m *Machine) Create(driver string, cpuCount string, memSize string, diskSize string) error {
m.out.Channel.Info.Printf("Creating a %s machine named '%s' with CPU(%s) MEM(%s) DISK(%s)...", driver, m.Name, cpuCount, memSize, diskSize)
m.out.Info("Creating a %s machine named '%s' with CPU(%s) MEM(%s) DISK(%s)...", driver, m.Name, cpuCount, memSize, diskSize)

boot2dockerURL := "https://github.com/boot2docker/boot2docker/releases/download/v" + util.GetRawCurrentDockerVersion() + "/boot2docker.iso"

Expand Down Expand Up @@ -72,7 +72,7 @@ func (m *Machine) Create(driver string, cpuCount string, memSize string, diskSiz
return fmt.Errorf("error creating machine '%s': %s", m.Name, err)
}

m.out.Channel.Info.Printf("Created docker-machine named '%s'...", m.Name)
m.out.Info("Created docker-machine named '%s'...", m.Name)
return nil
}

Expand All @@ -94,7 +94,7 @@ func (m Machine) CheckXhyveRequirements() error {
// Start boots the Docker Machine
func (m Machine) Start() error {
if !m.IsRunning() {
m.out.Channel.Verbose.Printf("The machine '%s' is not running, starting...", m.Name)
m.out.Verbose("The machine '%s' is not running, starting...", m.Name)

if err := util.StreamCommand("docker-machine", "start", m.Name); err != nil {
return fmt.Errorf("error starting machine '%s': %s", m.Name, err)
Expand Down Expand Up @@ -127,10 +127,10 @@ func (m Machine) WaitForDev() error {
for i := 1; i <= maxTries; i++ {
m.SetEnv()
if err := util.Command("docker", "ps").Run(); err == nil {
m.out.Channel.Verbose.Printf("Machine '%s' has started", m.Name)
m.out.Verbose("Machine '%s' has started", m.Name)
return nil
}
m.out.Channel.Warning.Printf("Docker daemon not running! Trying again in %d seconds. Try %d of %d. \n", sleepSecs, i, maxTries)
m.out.Warning("Docker daemon not running! Trying again in %d seconds. Try %d of %d. \n", sleepSecs, i, maxTries)
time.Sleep(time.Duration(sleepSecs) * time.Second)
}

Expand Down
2 changes: 1 addition & 1 deletion commands/project_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (cmd *ProjectCreate) RunGenerator(ctx *cli.Context, machine Machine, image
if e := util.StreamCommand("docker", "pull", image); e != nil {
cmd.out.Error("Project generator docker image failed to update. Using local cache if available: %s", image)
} else {
cmd.out.Warning("Project generator docker image is up-to-date: %s", image)
cmd.out.Info("Project generator docker image is up-to-date: %s", image)
}
} else if err == nil && ctx.Bool("no-update") {
cmd.out.Verbose("Automatic generator image update suppressed by --no-update option.")
Expand Down
20 changes: 10 additions & 10 deletions commands/project_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (cmd *ProjectSync) StartUnisonSync(ctx *cli.Context, volumeName string, con
// up and running. If the logfile does not exist, do not complain. If the
// filesystem cannot delete the file when it exists, it will lead to errors.
if err := util.RemoveFile(logFile, workingDir); err != nil {
cmd.out.Channel.Verbose.Printf("Could not remove Unison log file: %s: %s", logFile, err.Error())
cmd.out.Verbose("Could not remove Unison log file: %s: %s", logFile, err.Error())
}

// Initiate local Unison process.
Expand All @@ -179,10 +179,10 @@ func (cmd *ProjectSync) StartUnisonSync(ctx *cli.Context, volumeName string, con
unisonArgs = append(unisonArgs, "-ignore", ignore)
}
}
cmd.out.Channel.Verbose.Printf("Unison Args: %s", strings.Join(unisonArgs[:], " "))
cmd.out.Verbose("Unison Args: %s", strings.Join(unisonArgs[:], " "))
command := exec.Command("unison", unisonArgs...)
command.Dir = workingDir
cmd.out.Channel.Verbose.Printf("Sync execution - Working Directory: %s", workingDir)
cmd.out.Verbose("Sync execution - Working Directory: %s", workingDir)
if err = util.Convert(command).Start(); err != nil {
return cmd.Failure(fmt.Sprintf("Failure starting local Unison process: %v", err), "UNISON-START-FAILED", 13)
}
Expand All @@ -196,7 +196,7 @@ func (cmd *ProjectSync) StartUnisonSync(ctx *cli.Context, volumeName string, con

// SetupBindVolume will create minimal Docker Volumes for systems that have native container/volume support
func (cmd *ProjectSync) SetupBindVolume(volumeName string, workingDir string) error {
cmd.out.Channel.Info.Printf("Starting local bind volume: %s", volumeName)
cmd.out.Info("Starting local bind volume: %s", volumeName)
util.Command("docker", "volume", "rm", volumeName).Run()

volumeArgs := []string{
Expand All @@ -219,9 +219,10 @@ func (cmd *ProjectSync) RunStop(ctx *cli.Context) error {
if runtime.GOOS == "linux" {
return cmd.Success("No Unison container to stop, using local bind volume")
}

cmd.Config = NewProjectConfig()
if cmd.Config.NotEmpty() {
cmd.out.Channel.Verbose.Printf("Loaded project configuration from %s", cmd.Config.Path)
cmd.out.Verbose("Loaded project configuration from %s", cmd.Config.Path)
}

// Determine the working directory for CWD-sensitive operations.
Expand All @@ -231,13 +232,12 @@ func (cmd *ProjectSync) RunStop(ctx *cli.Context) error {
}

volumeName := cmd.GetVolumeName(cmd.Config, workingDir)
cmd.out.Channel.Verbose.Printf("Stopping sync with volume: %s", volumeName)
cmd.out.Info("Stopping Unison container")
cmd.out.Spin(fmt.Sprintf("Stopping Unison container (%s)", volumeName))
if err := util.Command("docker", "container", "stop", volumeName).Run(); err != nil {
return cmd.Failure(err.Error(), "SYNC-CONTAINER-FAILURE", 13)
}

return cmd.Success("Unison container stopped")
return cmd.Success(fmt.Sprintf("Unison container %s stopped", volumeName))
}

// GetVolumeName will find the volume name through a variety of fall backs
Expand Down Expand Up @@ -294,15 +294,15 @@ func (cmd *ProjectSync) WaitForUnisonContainer(containerName string, timeoutSeco
}
ip := strings.Trim(string(output), "\n")

cmd.out.Channel.Verbose.Printf("Checking for Unison network connection on %s %d", ip, unisonPort)
cmd.out.Verbose("Checking for Unison network connection on %s %d", ip, unisonPort)
for i := 1; i <= timeoutLoops; i++ {
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", ip, unisonPort))
if err == nil {
conn.Close()
return ip, nil
}

cmd.out.Channel.Info.Printf("Failure: %v", err)
cmd.out.Info("Failure: %v", err)
time.Sleep(timeoutLoopSleep)
}

Expand Down
4 changes: 2 additions & 2 deletions commands/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func (cmd *Prune) Commands() []cli.Command {

// Run executes the `rig prune` command
func (cmd *Prune) Run(c *cli.Context) error {
cmd.out.Info("Cleaning up Docker images and containers...")
cmd.out.Spin("Cleaning up unused Docker resources...")
if exitCode := util.PassthruCommand(exec.Command("docker", "system", "prune", "--all", "--volumes")); exitCode != 0 {
return cmd.Failure("Failure pruning Docker resources.", "COMMAND-ERROR", 13)
}

cmd.out.Info("Unused Docker images, containers, volumes, and networks cleaned up.")
return cmd.Success("")
}
5 changes: 3 additions & 2 deletions commands/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (cmd *Remove) Run(c *cli.Context) error {
cmd.out.Warning("Run 'rig data-backup' if you want to save your /data volume.")

if !util.AskYesNo("Are you sure you want to remove '" + cmd.machine.Name + "'") {
return cmd.Success("Remove was aborted")
cmd.out.Info("Remove was aborted")
return cmd.Success("")
}
}

Expand All @@ -63,6 +64,6 @@ func (cmd *Remove) Run(c *cli.Context) error {
return cmd.Failure(err.Error(), "MACHINE-REMOVE-FAILED", 12)
}

cmd.out.Info("Failed to remove the docker Virtual Machine")
cmd.out.Info("Removed the Docker Virtual Machine")
return cmd.Success(fmt.Sprintf("Machine '%s' removed", cmd.machine.Name))
}
4 changes: 2 additions & 2 deletions commands/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func (cmd *Restart) Commands() []cli.Command {
func (cmd *Restart) Run(c *cli.Context) error {
if util.SupportsNativeDocker() || cmd.machine.Exists() {
if util.SupportsNativeDocker() {
cmd.out.Info("Restarting Outrigger services")
cmd.out.Spin("Restarting Outrigger services")
} else {
cmd.out.Channel.Info.Printf("Restarting Outrigger machine '%s' and services", cmd.machine.Name)
cmd.out.Spin(fmt.Sprintf("Restarting Outrigger machine '%s' and services", cmd.machine.Name))
}

stop := Stop{cmd.BaseCommand}
Expand Down
3 changes: 2 additions & 1 deletion commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (cmd *Status) Commands() []cli.Command {
// Run executes the `rig status` command
func (cmd *Status) Run(c *cli.Context) error {
if util.SupportsNativeDocker() {
return cmd.Success("Status is not needed on Linux")
cmd.out.Info("Status is not needed on Linux")
return cmd.Success("")
}

if !cmd.machine.Exists() {
Expand Down
2 changes: 1 addition & 1 deletion commands/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (cmd *Upgrade) Run(c *cli.Context) error {
return cmd.Success(fmt.Sprintf("Machine '%s' has the same Docker version (%s) as your local Docker binary (%s). There is nothing to upgrade. If you wish to upgrade you'll need to install a newer version of the Docker binary before running the upgrade command.", cmd.machine.Name, machineDockerVersion, currentDockerVersion))
}

cmd.out.Channel.Info.Printf("Backing up to prepare for upgrade...")
cmd.out.Info("Backing up to prepare for upgrade...")
backup := &DataBackup{cmd.BaseCommand}
if err := backup.Run(c); err != nil {
return err
Expand Down