From b1321924485823af9aec2c372b7d1f6b566e8b22 Mon Sep 17 00:00:00 2001 From: z4yx Date: Sat, 28 Mar 2020 16:28:45 +0800 Subject: [PATCH] Add a debugging log level to tunasynctl --- cmd/tunasynctl/tunasynctl.go | 9 +++++++-- internal/logger.go | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/tunasynctl/tunasynctl.go b/cmd/tunasynctl/tunasynctl.go index 0d33651..dbdee81 100644 --- a/cmd/tunasynctl/tunasynctl.go +++ b/cmd/tunasynctl/tunasynctl.go @@ -32,7 +32,7 @@ const ( userCfgFile = "$HOME/.config/tunasync/ctl.conf" // user-specific conf ) -var logger = logging.MustGetLogger("tunasynctl-cmd") +var logger = logging.MustGetLogger("tunasynctl") var baseURL string var client *http.Client @@ -67,7 +67,7 @@ func loadConfig(cfgFile string, cfg *config) error { func initialize(c *cli.Context) error { // init logger - tunasync.InitLogger(c.Bool("verbose"), c.Bool("verbose"), false) + tunasync.InitLogger(c.Bool("verbose"), c.Bool("debug"), false) cfg := new(config) @@ -79,6 +79,7 @@ func initialize(c *cli.Context) error { if _, err := os.Stat(systemCfgFile); err == nil { loadConfig(systemCfgFile, cfg) } + logger.Debug("user config file: %s", os.ExpandEnv(userCfgFile)) if _, err := os.Stat(os.ExpandEnv(userCfgFile)); err == nil { loadConfig(os.ExpandEnv(userCfgFile), cfg) } @@ -462,6 +463,10 @@ func main() { Name: "verbose, v", Usage: "Enable verbosely logging", }, + cli.BoolFlag{ + Name: "debug", + Usage: "Enable debugging logging", + }, } cmdFlags := []cli.Flag{ cli.StringFlag{ diff --git a/internal/logger.go b/internal/logger.go index 346ea24..8716e01 100644 --- a/internal/logger.go +++ b/internal/logger.go @@ -24,12 +24,12 @@ func InitLogger(verbose, debug, withSystemd bool) { if debug { logging.SetLevel(logging.DEBUG, "tunasync") - logging.SetLevel(logging.DEBUG, "tunasynctl-cmd") + logging.SetLevel(logging.DEBUG, "tunasynctl") } else if verbose { logging.SetLevel(logging.INFO, "tunasync") - logging.SetLevel(logging.INFO, "tunasynctl-cmd") + logging.SetLevel(logging.INFO, "tunasynctl") } else { logging.SetLevel(logging.NOTICE, "tunasync") - logging.SetLevel(logging.NOTICE, "tunasynctl-cmd") + logging.SetLevel(logging.NOTICE, "tunasynctl") } }