diff --git a/Gopkg.lock b/Gopkg.lock index 5f9c1be..3f63948 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,12 +1,5 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - -[[projects]] - name = "github.com/sirupsen/logrus" - packages = ["."] - revision = "f006c2ac4710855cf0f916dd6b77acf6b048dc6e" - version = "v1.0.3" - [[projects]] branch = "master" name = "golang.org/x/crypto" diff --git a/api.go b/api.go index 848fae6..9063bea 100644 --- a/api.go +++ b/api.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "io" + "log/slog" "math" "net/http" "os" @@ -30,7 +31,6 @@ import ( "github.com/dell/goscaleio/api" types "github.com/dell/goscaleio/types/v1" - log "github.com/sirupsen/logrus" ) var ( @@ -44,6 +44,7 @@ var ( debug, _ = strconv.ParseBool(os.Getenv("GOSCALEIO_DEBUG")) showHTTP, _ = strconv.ParseBool(os.Getenv("GOSCALEIO_SHOWHTTP")) + logger = slog.New(slog.NewTextHandler(os.Stderr, nil)) ) // Client defines struct for Client @@ -79,7 +80,7 @@ func (c *Client) GetVersion() (string, error) { } defer func() { if err := resp.Body.Close(); err != nil { - doLog(log.WithError(err).Error, "") + doLog(logger.Error, err.Error()) } }() // parse the response @@ -147,13 +148,13 @@ func (c *Client) Authenticate(configConnect *ConfigConnect) (Cluster, error) { resp, err := c.api.DoAndGetResponseBody( context.Background(), http.MethodGet, "api/login", headers, nil, c.configConnect.Version) if err != nil { - doLog(log.WithError(err).Error, "") + doLog(logger.Error, err.Error()) return Cluster{}, err } defer func() { if err := resp.Body.Close(); err != nil { - doLog(log.WithError(err).Error, "") + doLog(logger.Error, err.Error()) } }() @@ -204,9 +205,9 @@ func (c *Client) getJSONWithRetry( // check if we need to authenticate if e, ok := err.(*types.Error); ok { - doLog(log.WithError(err).Debug, fmt.Sprintf("Got JSON error: %+v", e)) + doLog(logger.Debug, fmt.Sprintf("Got JSON error: %+v", e)) if e.HTTPStatusCode == 401 { - doLog(log.Info, "Need to re-auth") + doLog(logger.Info, "Need to re-auth") // Authenticate then try again if _, err := c.Authenticate(c.configConnect); err != nil { return fmt.Errorf("Error Authenticating: %s", err) @@ -215,7 +216,7 @@ func (c *Client) getJSONWithRetry( context.Background(), method, uri, headers, body, resp, c.configConnect.Version) } } - doLog(log.WithError(err).Error, "returning error") + doLog(logger.Error, err.Error()) return err } @@ -252,7 +253,7 @@ func (c *Client) getStringWithRetry( checkResponse := func(resp *http.Response) (string, bool, error) { defer func() { if err := resp.Body.Close(); err != nil { - doLog(log.WithError(err).Error, "") + doLog(logger.Error, err.Error()) } }() @@ -282,7 +283,7 @@ func (c *Client) getStringWithRetry( s, retry, httpErr := checkResponse(resp) if httpErr != nil { if retry { - doLog(log.Info, "need to re-auth") + doLog(logger.Info, "need to re-auth") // Authenticate then try again if _, err = c.Authenticate(c.configConnect); err != nil { return "", fmt.Errorf("Error Authenticating: %s", err) @@ -349,11 +350,10 @@ func NewClientWithArgs( "debug": debug, "showHTTP": showHTTP, } - - doLog(log.WithFields(fields).Debug, "goscaleio client init") + doLog(logger.Debug, fmt.Sprintf("goscaleio client init, Fields: %+v", fields)) if endpoint == "" { - doLog(log.WithFields(fields).Error, "endpoint is required") + doLog(logger.Error, fmt.Sprintf("endpoint is required, Fields: %+v", fields)) return nil, withFields(fields, "endpoint is required") } @@ -371,7 +371,7 @@ func NewClientWithArgs( ac, err := api.New(context.Background(), endpoint, opts, debug) if err != nil { - doLog(log.WithError(err).Error, "Unable to create HTTP client") + doLog(logger.Error, fmt.Sprintf("Unable to create HTTP client: %s", err.Error())) return nil, err } @@ -430,7 +430,7 @@ func withFieldsE( } func doLog( - l func(args ...interface{}), + l func(msg string, args ...any), msg string, ) { if debug { diff --git a/api/api.go b/api/api.go index c2a17c6..3dcb46c 100644 --- a/api/api.go +++ b/api/api.go @@ -21,14 +21,14 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" + "os" "strconv" "strings" "time" - log "github.com/sirupsen/logrus" - types "github.com/dell/goscaleio/types/v1" ) @@ -46,6 +46,7 @@ const ( var ( errNewClient = errors.New("missing endpoint") errSysCerts = errors.New("Unable to initialize cert pool from system") + logger = slog.New(slog.NewTextHandler(os.Stderr, nil)) ) // Client is an API client. @@ -271,7 +272,7 @@ func (c *client) DoWithHeaders( defer func() { if err := res.Body.Close(); err != nil { - c.doLog(log.WithError(err).Error, "") + c.doLog(logger.Error, err.Error()) } }() @@ -285,9 +286,7 @@ func (c *client) DoWithHeaders( } dec := json.NewDecoder(res.Body) if err = dec.Decode(resp); err != nil && err != io.EOF { - c.doLog(log.WithError(err).Error, - fmt.Sprintf("Unable to decode response into %+v", - resp)) + c.doLog(logger.Error, fmt.Sprintf("Error: %s Unable to decode response into %+v", err.Error(), resp)) return err } default: @@ -340,7 +339,7 @@ func (c *client) DoAndGetResponseBody( defer func() { if err := r.Close(); err != nil { - c.doLog(log.WithError(err).Error, "") + c.doLog(logger.Error, err.Error()) } }() @@ -456,7 +455,7 @@ func (c *client) ParseJSONError(r *http.Response) error { } func (c *client) doLog( - l func(args ...interface{}), + l func(msg string, args ...any), msg string, ) { if c.debug { diff --git a/api/api_logging.go b/api/api_logging.go index 94a7383..431ff95 100644 --- a/api/api_logging.go +++ b/api/api_logging.go @@ -21,8 +21,6 @@ import ( "net/http" "net/http/httputil" "strings" - - log "github.com/sirupsen/logrus" ) func isBinOctetBody(h http.Header) bool { @@ -32,10 +30,8 @@ func isBinOctetBody(h http.Header) bool { func logRequest( _ context.Context, req *http.Request, - lf func(func(args ...interface{}), string), + lf func(func(msg string, args ...any), string), ) { - log.SetLevel(log.DebugLevel) - w := &bytes.Buffer{} fmt.Fprintln(w) @@ -51,19 +47,16 @@ func logRequest( if err := WriteIndented(w, buf); err != nil { fmt.Printf("WriteIndented returned error: %s", err.Error()) } - - fmt.Fprintln(w) - - lf(log.Debug, w.String()) + if lf != nil { + lf(logger.Debug, w.String()) + } } func logResponse( _ context.Context, res *http.Response, - _ func(func(args ...interface{}), string), + lf func(func(msg string, args ...any), string), ) { - log.SetLevel(log.DebugLevel) - w := &bytes.Buffer{} fmt.Fprintln(w) @@ -89,8 +82,9 @@ func logResponse( } fmt.Fprintln(w, scanner.Text()) } - - log.Debug(w.String()) + if lf != nil { + lf(logger.Debug, w.String()) + } } // WriteIndentedN indents all lines n spaces. diff --git a/api/api_logging_test.go b/api/api_logging_test.go index 6e4dfee..10f5068 100644 --- a/api/api_logging_test.go +++ b/api/api_logging_test.go @@ -22,8 +22,6 @@ import ( "net/http" "strings" "testing" - - log "github.com/sirupsen/logrus" ) func TestIsBinOctetBody(t *testing.T) { @@ -185,12 +183,8 @@ func TestLogResponse(_ *testing.T) { logResponse(context.Background(), res, nil) } -func logChecker(level log.Level, msg string) func(func(args ...interface{}), string) { - return func(lf func(args ...interface{}), message string) { - if level != log.DebugLevel { - // If the log level is not DebugLevel, call the logging function with an error message - lf(fmt.Sprintf("Expected debug level, got %v", level)) - } +func logChecker(msg string) func(func(msg string, args ...any), string) { + return func(lf func(msg string, args ...any), message string) { if !strings.Contains(msg, "GOSCALEIO HTTP REQUEST") { // If the message does not contain the expected string, call the logging function with an error message lf(fmt.Sprintf("Expected request log, got %s", msg)) @@ -207,7 +201,7 @@ func TestLogRequest(t *testing.T) { if err != nil { t.Fatal(err) } - logFunc := logChecker(log.DebugLevel, "GOSCALEIO HTTP REQUEST") + logFunc := logChecker("GOSCALEIO HTTP REQUEST") logRequest(context.Background(), req, logFunc) // Test case: Error in dumpRequest diff --git a/deploy.go b/deploy.go index e346595..e1bb18c 100644 --- a/deploy.go +++ b/deploy.go @@ -34,7 +34,6 @@ import ( "github.com/dell/goscaleio/api" types "github.com/dell/goscaleio/types/v1" - log "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" ) @@ -144,7 +143,7 @@ func (gc *GatewayClient) NewTokenGeneration() (string, error) { defer func() { if err := resp.Body.Close(); err != nil { - doLog(log.WithError(err).Error, "") + doLog(logger.Error, err.Error()) } }() diff --git a/drv_cfg.go b/drv_cfg.go index 798785f..6362524 100644 --- a/drv_cfg.go +++ b/drv_cfg.go @@ -1,3 +1,5 @@ +//go:build !windows + // Copyright © 2021 - 2022 Dell Inc. or its subsidiaries. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/go.mod b/go.mod index d371967..1fd0e7c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/dell/goscaleio require ( github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 - github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -11,7 +10,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.27.0 // indirect ) go 1.23 diff --git a/go.sum b/go.sum index 7bb202a..cad2f85 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,3 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -7,17 +6,9 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/inttests/drv_cfg_test.go b/inttests/drv_cfg_test.go index b7956a6..dcc0a4f 100644 --- a/inttests/drv_cfg_test.go +++ b/inttests/drv_cfg_test.go @@ -1,3 +1,5 @@ +//go:build !windows + // Copyright © 2021 - 2022 Dell Inc. or its subsidiaries. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/inttests/fs_test.go b/inttests/fs_test.go index a36094d..1ae3d6c 100644 --- a/inttests/fs_test.go +++ b/inttests/fs_test.go @@ -18,7 +18,6 @@ import ( "testing" "github.com/dell/goscaleio" - // log "github.com/sirupsen/logrus" types "github.com/dell/goscaleio/types/v1" "github.com/stretchr/testify/assert" ) diff --git a/inttests/protectiondomain_test.go b/inttests/protectiondomain_test.go index f4e1af2..ae8bfb7 100644 --- a/inttests/protectiondomain_test.go +++ b/inttests/protectiondomain_test.go @@ -19,7 +19,6 @@ import ( "github.com/dell/goscaleio" types "github.com/dell/goscaleio/types/v1" - log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) @@ -63,11 +62,9 @@ func getAllProtectionDomains(t *testing.T) []*goscaleio.ProtectionDomain { system := getSystem() assert.NotNil(t, system) - log.SetLevel(log.DebugLevel) pd, err := system.GetProtectionDomain("") assert.Nil(t, err) assert.NotZero(t, len(pd)) - log.SetLevel(log.InfoLevel) var allDomains []*goscaleio.ProtectionDomain diff --git a/inttests/replication_test.go b/inttests/replication_test.go index 0060a3e..1f3d31c 100644 --- a/inttests/replication_test.go +++ b/inttests/replication_test.go @@ -28,7 +28,6 @@ import ( "github.com/dell/goscaleio" siotypes "github.com/dell/goscaleio/types/v1" - log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) @@ -349,7 +348,6 @@ func TestCreateReplicationConsistencyGroup(t *testing.T) { rcgResp, err := C.CreateReplicationConsistencyGroup(rcgPayload) assert.Nil(t, err) - log.Debugf("RCG ID: %s", rcgResp.ID) rep.rcgID = rcgResp.ID time.Sleep(5 * time.Second) diff --git a/service.go b/service.go index 3920420..456daf0 100644 --- a/service.go +++ b/service.go @@ -25,7 +25,6 @@ import ( types "github.com/dell/goscaleio/types/v1" "github.com/google/uuid" - log "github.com/sirupsen/logrus" ) // DeployService used to deploy service @@ -460,7 +459,7 @@ func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken boo defer func() { if err := resp.Body.Close(); err != nil { - doLog(log.WithError(err).Error, "") + doLog(logger.Error, err.Error()) } }()