Add a debugging log level to tunasynctl

This commit is contained in:
z4yx 2020-03-28 16:28:45 +08:00
parent 91209cab60
commit b132192448
2 changed files with 10 additions and 5 deletions

View File

@ -32,7 +32,7 @@ const (
userCfgFile = "$HOME/.config/tunasync/ctl.conf" // user-specific conf userCfgFile = "$HOME/.config/tunasync/ctl.conf" // user-specific conf
) )
var logger = logging.MustGetLogger("tunasynctl-cmd") var logger = logging.MustGetLogger("tunasynctl")
var baseURL string var baseURL string
var client *http.Client var client *http.Client
@ -67,7 +67,7 @@ func loadConfig(cfgFile string, cfg *config) error {
func initialize(c *cli.Context) error { func initialize(c *cli.Context) error {
// init logger // init logger
tunasync.InitLogger(c.Bool("verbose"), c.Bool("verbose"), false) tunasync.InitLogger(c.Bool("verbose"), c.Bool("debug"), false)
cfg := new(config) cfg := new(config)
@ -79,6 +79,7 @@ func initialize(c *cli.Context) error {
if _, err := os.Stat(systemCfgFile); err == nil { if _, err := os.Stat(systemCfgFile); err == nil {
loadConfig(systemCfgFile, cfg) loadConfig(systemCfgFile, cfg)
} }
logger.Debug("user config file: %s", os.ExpandEnv(userCfgFile))
if _, err := os.Stat(os.ExpandEnv(userCfgFile)); err == nil { if _, err := os.Stat(os.ExpandEnv(userCfgFile)); err == nil {
loadConfig(os.ExpandEnv(userCfgFile), cfg) loadConfig(os.ExpandEnv(userCfgFile), cfg)
} }
@ -462,6 +463,10 @@ func main() {
Name: "verbose, v", Name: "verbose, v",
Usage: "Enable verbosely logging", Usage: "Enable verbosely logging",
}, },
cli.BoolFlag{
Name: "debug",
Usage: "Enable debugging logging",
},
} }
cmdFlags := []cli.Flag{ cmdFlags := []cli.Flag{
cli.StringFlag{ cli.StringFlag{

View File

@ -24,12 +24,12 @@ func InitLogger(verbose, debug, withSystemd bool) {
if debug { if debug {
logging.SetLevel(logging.DEBUG, "tunasync") logging.SetLevel(logging.DEBUG, "tunasync")
logging.SetLevel(logging.DEBUG, "tunasynctl-cmd") logging.SetLevel(logging.DEBUG, "tunasynctl")
} else if verbose { } else if verbose {
logging.SetLevel(logging.INFO, "tunasync") logging.SetLevel(logging.INFO, "tunasync")
logging.SetLevel(logging.INFO, "tunasynctl-cmd") logging.SetLevel(logging.INFO, "tunasynctl")
} else { } else {
logging.SetLevel(logging.NOTICE, "tunasync") logging.SetLevel(logging.NOTICE, "tunasync")
logging.SetLevel(logging.NOTICE, "tunasynctl-cmd") logging.SetLevel(logging.NOTICE, "tunasynctl")
} }
} }