Skip to content

Commit 246c8b9

Browse files
committed
refactor: remove duplicate logs
- 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
1 parent f14516b commit 246c8b9

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ func main() {
3737
}
3838

3939
if conf.PullOnStart {
40+
log.Println("pulling changes from remote...")
4041
GitPull(conf)
4142
}
4243

43-
log.Println("[INFO] Watching for changes...")
44-
44+
log.Println("Watching for changes...")
4545
for true {
4646
if GitRepoHasChanges(conf) {
4747
GitAdd(conf)
4848
GitCommit(conf)
4949
GitPush(conf)
50+
log.Printf("All done, waiting for %d seconds before checking for changes again...", conf.BackupInterval)
5051
} else {
51-
log.Println("[INFO] No changes to commit, waiting for next iteration...")
52+
log.Println("No changes to commit, waiting for next iteration...")
5253
}
5354
time.Sleep(time.Duration(conf.BackupInterval) * time.Second)
5455
}

sync.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ func gitAffectedFiles(conf Config) []string {
4545
}
4646
res = append(res, strings.TrimSpace(file[1:])+" ("+change+")")
4747
}
48-
DebugLog(conf, fmt.Sprintf("parsed '%d' changed files...", len(res)))
48+
var c rune
49+
if len(res) > 1 {
50+
c = 's'
51+
}
52+
DebugLog(conf, fmt.Sprintf("parsed '%d' changed file%c...", len(res), c))
4953
return res
5054
}
5155

5256
func GitPull(conf Config) {
53-
DebugLog(conf, "pulling changes from remote...")
5457
_, err := runCmd([]string{"git", "pull"})
5558
if err != nil {
5659
log.Println("[WARNING] pulling changes from remote failed: ", err)
@@ -89,14 +92,13 @@ func GitPush(conf Config) {
8992
log.Println("[WARNING] push to remote failed: ", err)
9093
return
9194
}
92-
log.Println("[INFO][PUSH]: pushed commits to remote...")
95+
log.Println("pushed commits to remote...")
9396
}
9497

9598
// makes a commit
9699
func GitCommit(conf Config) {
97-
DebugLog(conf, "making commit...")
98100
commitContent := generateCommitContent(conf)
99-
log.Println("[INFO][COMMIT]:", strconv.Quote(strings.Join(commitContent, " ")))
101+
log.Println("new commit:", strconv.Quote(strings.Join(commitContent, " ")))
100102
_, err := runCmd(commitContent)
101103
if err != nil {
102104
log.Println("[WARNING] commiting failed: ", err)
@@ -122,6 +124,5 @@ func generateCommitContent(conf Config) []string {
122124
commit = append(commit, strings.Split(conf.CommitCommand, " ")...)
123125
}
124126
commit = append(commit, commitContent)
125-
DebugLog(conf, fmt.Sprintf("generated commit content. (%s)", strconv.Quote(strings.Join(commit, " "))))
126127
return commit
127128
}

util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func getConfig() Config {
8484
confContent, err := os.ReadFile(confFile)
8585
if err != nil {
8686
log.Println("[WARNING] xgs config not found: ", err)
87-
log.Println("[INFO] using fallback config...")
87+
log.Println("using fallback config...")
8888
return fallbackConf
8989
}
9090

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

0 commit comments

Comments
 (0)