Skip to content

Commit

Permalink
Update: Added log with timestamp rather than just using log.Printf()
Browse files Browse the repository at this point in the history
  • Loading branch information
dtchanpura committed Apr 27, 2019
1 parent 99aa430 commit fa04f77
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var versionCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(versionCmd)
version = "0.8.0-alpha"
buildDate = "2019-04-12 11:18:28 IST"
version = "0.7.2"
buildDate = "2019-04-27 10:42:09 IST"
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
15 changes: 12 additions & 3 deletions utils/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"os/exec"
"time"

"github.com/dtchanpura/deployment-agent/constants"
)
Expand All @@ -16,16 +17,24 @@ func ExecuteScript(workdir string, execpath string, args ...string) error {
if dirInfo, err := os.Stat(workdir); err == nil && dirInfo.IsDir() {
cmd.Dir = workdir
} else {
log.Println(err)
logWithTimestampln(err.Error())
}
// err := cmd.Run()
outputBytes, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Command Error: %s\n", string(outputBytes[:]))
logWithTimestampf("Command Error: %s\n", string(outputBytes[:]))
return err
}
log.Printf("Command Output: %s\n", string(outputBytes[:]))
logWithTimestampf("Command Output: %s\n", string(outputBytes[:]))
return nil
}
return errors.New(constants.ErrorFileNotExecutable)
}

func logWithTimestampf(message string, args ...interface{}) {
log.Printf(time.Now().Format("[ 2006/01/02 15:04:05 ] ")+message, args...)
}

func logWithTimestampln(message string) {
logWithTimestampf(message + "\n")
}
8 changes: 8 additions & 0 deletions utils/functions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package utils

import "testing"

func TestLog(t *testing.T) {
// t.SkipNow()
logWithTimestampln("testing")
}

0 comments on commit fa04f77

Please sign in to comment.