From 4d461bd17282305c718478a231075479b5abfd97 Mon Sep 17 00:00:00 2001 From: Phy Date: Mon, 23 Mar 2020 01:20:49 -0400 Subject: [PATCH 1/3] Use logger to print some debug messages than fmt.print --- cmd/tunasynctl/tunasynctl.go | 4 ++-- worker/cmd_provider.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/tunasynctl/tunasynctl.go b/cmd/tunasynctl/tunasynctl.go index e5a8a5e..46af162 100644 --- a/cmd/tunasynctl/tunasynctl.go +++ b/cmd/tunasynctl/tunasynctl.go @@ -55,6 +55,7 @@ type config struct { func loadConfig(cfgFile string, cfg *config) error { if cfgFile != "" { + logger.Infof("Loading config: %s", cfgFile) if _, err := toml.DecodeFile(cfgFile, cfg); err != nil { logger.Errorf(err.Error()) return err @@ -78,7 +79,6 @@ func initialize(c *cli.Context) error { if _, err := os.Stat(systemCfgFile); err == nil { loadConfig(systemCfgFile, cfg) } - fmt.Println(os.ExpandEnv(userCfgFile)) if _, err := os.Stat(os.ExpandEnv(userCfgFile)); err == nil { loadConfig(os.ExpandEnv(userCfgFile), cfg) } @@ -185,7 +185,7 @@ func listJobs(c *cli.Context) error { fmt.Sprintf("Error printing out informations: %s", err.Error()), 1) } - fmt.Printf(string(b)) + fmt.Print(string(b)) return nil } diff --git a/worker/cmd_provider.go b/worker/cmd_provider.go index b5d39ad..92d82ec 100644 --- a/worker/cmd_provider.go +++ b/worker/cmd_provider.go @@ -96,7 +96,7 @@ func (p *cmdProvider) Run() error { } if p.failOnMatch != nil { matches, err := internal.FindAllSubmatchInFile(p.LogFile(), p.failOnMatch) - fmt.Printf("FindAllSubmatchInFile: %q\n", matches) + logger.Infof("FindAllSubmatchInFile: %q\n", matches) if err != nil { return err } From a44891d3e873ca666aa5453d08b42507985c0904 Mon Sep 17 00:00:00 2001 From: Phy Date: Mon, 23 Mar 2020 01:21:16 -0400 Subject: [PATCH 2/3] Set proper logging level on tunasynctl-cmd --- internal/logger.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/logger.go b/internal/logger.go index f733947..346ea24 100644 --- a/internal/logger.go +++ b/internal/logger.go @@ -24,9 +24,12 @@ func InitLogger(verbose, debug, withSystemd bool) { if debug { logging.SetLevel(logging.DEBUG, "tunasync") + logging.SetLevel(logging.DEBUG, "tunasynctl-cmd") } else if verbose { logging.SetLevel(logging.INFO, "tunasync") + logging.SetLevel(logging.INFO, "tunasynctl-cmd") } else { logging.SetLevel(logging.NOTICE, "tunasync") + logging.SetLevel(logging.NOTICE, "tunasynctl-cmd") } } From 5c01e3fa22e331bcfd0e64389b54b604a27279d3 Mon Sep 17 00:00:00 2001 From: Phy Date: Mon, 23 Mar 2020 10:19:55 -0400 Subject: [PATCH 3/3] Use fmt.Println for cli JSON output --- cmd/tunasynctl/tunasynctl.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/tunasynctl/tunasynctl.go b/cmd/tunasynctl/tunasynctl.go index 46af162..0d33651 100644 --- a/cmd/tunasynctl/tunasynctl.go +++ b/cmd/tunasynctl/tunasynctl.go @@ -135,7 +135,7 @@ func listWorkers(c *cli.Context) error { err.Error()), 1) } - fmt.Print(string(b)) + fmt.Println(string(b)) return nil } @@ -185,7 +185,7 @@ func listJobs(c *cli.Context) error { fmt.Sprintf("Error printing out informations: %s", err.Error()), 1) } - fmt.Print(string(b)) + fmt.Println(string(b)) return nil }