Skip to content

Commit

Permalink
refactor: remove duplicate logs
Browse files Browse the repository at this point in the history
- remove all '[INFO]' prefix from logs
- only add the 's' to 'file' if more than 1 file was parsed (gitAffectedFiles)
- new log after xgs is done with changes and the current iteration
  • Loading branch information
xNaCly committed Jan 23, 2023
1 parent f14516b commit 246c8b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ func main() {
}

if conf.PullOnStart {
log.Println("pulling changes from remote...")
GitPull(conf)
}

log.Println("[INFO] Watching for changes...")

log.Println("Watching for changes...")
for true {
if GitRepoHasChanges(conf) {
GitAdd(conf)
GitCommit(conf)
GitPush(conf)
log.Printf("All done, waiting for %d seconds before checking for changes again...", conf.BackupInterval)
} else {
log.Println("[INFO] No changes to commit, waiting for next iteration...")
log.Println("No changes to commit, waiting for next iteration...")
}
time.Sleep(time.Duration(conf.BackupInterval) * time.Second)
}
Expand Down
13 changes: 7 additions & 6 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ func gitAffectedFiles(conf Config) []string {
}
res = append(res, strings.TrimSpace(file[1:])+" ("+change+")")
}
DebugLog(conf, fmt.Sprintf("parsed '%d' changed files...", len(res)))
var c rune
if len(res) > 1 {
c = 's'
}
DebugLog(conf, fmt.Sprintf("parsed '%d' changed file%c...", len(res), c))
return res
}

func GitPull(conf Config) {
DebugLog(conf, "pulling changes from remote...")
_, err := runCmd([]string{"git", "pull"})
if err != nil {
log.Println("[WARNING] pulling changes from remote failed: ", err)
Expand Down Expand Up @@ -89,14 +92,13 @@ func GitPush(conf Config) {
log.Println("[WARNING] push to remote failed: ", err)
return
}
log.Println("[INFO][PUSH]: pushed commits to remote...")
log.Println("pushed commits to remote...")
}

// makes a commit
func GitCommit(conf Config) {
DebugLog(conf, "making commit...")
commitContent := generateCommitContent(conf)
log.Println("[INFO][COMMIT]:", strconv.Quote(strings.Join(commitContent, " ")))
log.Println("new commit:", strconv.Quote(strings.Join(commitContent, " ")))
_, err := runCmd(commitContent)
if err != nil {
log.Println("[WARNING] commiting failed: ", err)
Expand All @@ -122,6 +124,5 @@ func generateCommitContent(conf Config) []string {
commit = append(commit, strings.Split(conf.CommitCommand, " ")...)
}
commit = append(commit, commitContent)
DebugLog(conf, fmt.Sprintf("generated commit content. (%s)", strconv.Quote(strings.Join(commit, " "))))
return commit
}
4 changes: 2 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func getConfig() Config {
confContent, err := os.ReadFile(confFile)
if err != nil {
log.Println("[WARNING] xgs config not found: ", err)
log.Println("[INFO] using fallback config...")
log.Println("using fallback config...")
return fallbackConf
}

Expand All @@ -93,7 +93,7 @@ func getConfig() Config {
err = json.Unmarshal(confContent, &resConfig)
if err != nil {
log.Println("[WARNING] couldn't parse config", err)
log.Println("[INF] using fallback config...")
log.Println("using fallback config...")
return fallbackConf
}
return resConfig
Expand Down

0 comments on commit 246c8b9

Please sign in to comment.