diff --git a/client.go b/client.go index 70eec42..d1d3326 100644 --- a/client.go +++ b/client.go @@ -17,7 +17,7 @@ func Post(reqUrl string, auth string, body interface{}) (respBodyObj ResponseBod log.WithFields(log.Fields{ "url": reqUrl, "body": string(postBody), - }).Debug("The request details") + }).Trace("The request details") req, err := http.NewRequest("POST", reqUrl, requestBody) if err != nil { return @@ -34,7 +34,7 @@ func Get(reqUrl string, auth string) (respBodyObj ResponseBody, err error) { } log.WithFields(log.Fields{ "url": reqUrl, - }).Debug("The request details") + }).Trace("The request details") req.Header.Set("Content-Type", "application/json") req.Header.Set(AuthHeaderKey(auth), auth) return handleResp(req) @@ -48,11 +48,11 @@ func Delete(reqUrl string, auth string, body interface{}) (respBodyObj ResponseB log.WithFields(log.Fields{ "url": reqUrl, "body": string(postBody), - }).Debug("The request details") + }).Trace("The request details") } else { log.WithFields(log.Fields{ "url": reqUrl, - }).Debug("The request details") + }).Trace("The request details") } var req *http.Request if requestBody != nil { @@ -86,7 +86,7 @@ func handleResp(req *http.Request) (respBodyObj ResponseBody, err error) { } log.WithFields(log.Fields{ "body": string(respBody), - }).Debug("The response body") + }).Trace("The response body") err = json.Unmarshal(respBody, &respBodyObj) if err != nil { log.Fatalln("There was error while parsing the response from server. Exiting...", err) diff --git a/docs/docs/cli.md b/docs/docs/cli.md index f408c35..047869b 100644 --- a/docs/docs/cli.md +++ b/docs/docs/cli.md @@ -52,7 +52,7 @@ harness-upgrade [global options] command [command options] [arguments...] | --target-api-key `API_KEY` | `API_KEY` for the target account to authenticate & authorise the migration. | | --load `FILE` | `FILE` to load flags from | | --insecure | allow insecure API requests. This is automatically set to true if environment is Dev (default: false) | -| --debug | print debug level logs (default: false) | +| --log-level | set the log level. Possible values - trace, debug, info, warn, error, fatal, panic. Default is `info` | | --json | log as JSON instead of standard ASCII formatter (default: false). | | --help, -h | show help. | | --version, -v | print the version | diff --git a/main.go b/main.go index bb798db..7e36d1d 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ var migrationReq = struct { TriggerIds string `survey:"triggerIds"` File string `survey:"load"` IdentifierCase string `survey:"identifierCase"` - Debug bool `survey:"debug"` + LogLevel string `survey:"logLevel"` Json bool `survey:"json"` AllowInsecureReq bool `survey:"insecure"` ProjectName string `survey:"projectName"` @@ -85,9 +85,14 @@ func logMigrationDetails() { } func cliWrapper(fn cliFnWrapper, ctx *cli.Context) error { - if migrationReq.Debug { - log.SetLevel(log.DebugLevel) + if len(migrationReq.LogLevel) > 0 { + level, err := log.ParseLevel(migrationReq.LogLevel) + if err != nil { + log.Fatal("Invalid log level") + } + log.SetLevel(level) } + if migrationReq.Json { log.SetFormatter(&log.JSONFormatter{}) } @@ -194,10 +199,11 @@ func main() { Usage: "allow insecure API requests. This is automatically set to true if environment is Dev", Destination: &migrationReq.AllowInsecureReq, }), - altsrc.NewBoolFlag(&cli.BoolFlag{ - Name: "debug", - Usage: "print debug level logs", - Destination: &migrationReq.Debug, + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "log-level", + Usage: "set the log level. Possible values - trace, debug, info, warn, error, fatal, panic. Default is `info`", + Destination: &migrationReq.LogLevel, + DefaultText: "info", }), altsrc.NewBoolFlag(&cli.BoolFlag{ Name: "json",