From 6fd63e920ad97b8ff1ab3739a42de2f26b925145 Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Fri, 2 Feb 2024 01:13:57 +0100 Subject: [PATCH] log: Use error log type instead of Application/MinIO type (#18930) * log: Use error log type instead of Application/MinIO type Also bump github.com/shirou/gopsutil version to address cross compilation issues. * Apply suggestions from code review Co-authored-by: Aditya Manthramurthy --------- Co-authored-by: Anis Eleuch Co-authored-by: Harshavardhana Co-authored-by: Aditya Manthramurthy --- cmd/admin-handlers-config-kv.go | 6 ++-- cmd/admin-handlers-idp-config.go | 2 +- cmd/admin-handlers-idp-ldap.go | 2 +- cmd/admin-handlers.go | 6 ++-- cmd/auth-handler.go | 6 ++-- cmd/common-main.go | 2 +- cmd/consolelogger.go | 2 +- cmd/endpoint.go | 10 +++--- cmd/erasure-multipart.go | 2 +- cmd/erasure-object.go | 4 +-- cmd/sts-errors.go | 2 +- cmd/test-utils_test.go | 4 +-- go.mod | 8 ++--- go.sum | 16 ++++----- internal/crypto/key_test.go | 8 ++--- internal/crypto/metadata_test.go | 8 ++--- internal/logger/console.go | 10 +++--- internal/logger/logger.go | 42 +++++++---------------- internal/logger/target/console/console.go | 2 +- 19 files changed, 63 insertions(+), 79 deletions(-) diff --git a/cmd/admin-handlers-config-kv.go b/cmd/admin-handlers-config-kv.go index 369e07bbf..dd500d6a2 100644 --- a/cmd/admin-handlers-config-kv.go +++ b/cmd/admin-handlers-config-kv.go @@ -58,7 +58,7 @@ func (a adminAPIHandlers) DelConfigKVHandler(w http.ResponseWriter, r *http.Requ password := cred.SecretKey kvBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength)) if err != nil { - logger.LogIf(ctx, err, logger.Application) + logger.LogIf(ctx, err, logger.ErrorKind) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL) return } @@ -162,7 +162,7 @@ func (a adminAPIHandlers) SetConfigKVHandler(w http.ResponseWriter, r *http.Requ password := cred.SecretKey kvBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength)) if err != nil { - logger.LogIf(ctx, err, logger.Application) + logger.LogIf(ctx, err, logger.ErrorKind) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL) return } @@ -443,7 +443,7 @@ func (a adminAPIHandlers) SetConfigHandler(w http.ResponseWriter, r *http.Reques password := cred.SecretKey kvBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength)) if err != nil { - logger.LogIf(ctx, err, logger.Application) + logger.LogIf(ctx, err, logger.ErrorKind) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL) return } diff --git a/cmd/admin-handlers-idp-config.go b/cmd/admin-handlers-idp-config.go index 2e59ebf0a..c054b0d34 100644 --- a/cmd/admin-handlers-idp-config.go +++ b/cmd/admin-handlers-idp-config.go @@ -60,7 +60,7 @@ func addOrUpdateIDPHandler(ctx context.Context, w http.ResponseWriter, r *http.R password := cred.SecretKey reqBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength)) if err != nil { - logger.LogIf(ctx, err, logger.Application) + logger.LogIf(ctx, err, logger.ErrorKind) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL) return } diff --git a/cmd/admin-handlers-idp-ldap.go b/cmd/admin-handlers-idp-ldap.go index 46f490ded..29578638d 100644 --- a/cmd/admin-handlers-idp-ldap.go +++ b/cmd/admin-handlers-idp-ldap.go @@ -132,7 +132,7 @@ func (a adminAPIHandlers) AttachDetachPolicyLDAP(w http.ResponseWriter, r *http. password := cred.SecretKey reqBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength)) if err != nil { - logger.LogIf(ctx, err, logger.Application) + logger.LogIf(ctx, err, logger.ErrorKind) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL) return } diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 9b1e01568..9fe8c294d 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -451,7 +451,7 @@ func (a adminAPIHandlers) ServiceHandler(w http.ResponseWriter, r *http.Request) case madmin.ServiceActionUnfreeze: serviceSig = serviceUnFreeze default: - logger.LogIf(ctx, fmt.Errorf("Unrecognized service action %s requested", action), logger.Application) + logger.LogIf(ctx, fmt.Errorf("Unrecognized service action %s requested", action), logger.ErrorKind) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrMalformedPOSTRequest), r.URL) return } @@ -534,7 +534,7 @@ func (a adminAPIHandlers) ServiceV2Handler(w http.ResponseWriter, r *http.Reques case madmin.ServiceActionUnfreeze: serviceSig = serviceUnFreeze default: - logger.LogIf(ctx, fmt.Errorf("Unrecognized service action %s requested", action), logger.Application) + logger.LogIf(ctx, fmt.Errorf("Unrecognized service action %s requested", action), logger.ErrorKind) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrMalformedPOSTRequest), r.URL) return } @@ -1239,7 +1239,7 @@ func extractHealInitParams(vars map[string]string, qParms url.Values, r io.Reade if hip.clientToken == "" { jerr := json.NewDecoder(r).Decode(&hip.hs) if jerr != nil { - logger.LogIf(GlobalContext, jerr, logger.Application) + logger.LogIf(GlobalContext, jerr, logger.ErrorKind) err = ErrRequestBodyParse return } diff --git a/cmd/auth-handler.go b/cmd/auth-handler.go index 9537970d7..6621bda38 100644 --- a/cmd/auth-handler.go +++ b/cmd/auth-handler.go @@ -257,7 +257,7 @@ func getClaimsFromTokenWithSecret(token, secret string) (map[string]interface{}, if err != nil { // Base64 decoding fails, we should log to indicate // something is malforming the request sent by client. - logger.LogIf(GlobalContext, err, logger.Application) + logger.LogIf(GlobalContext, err, logger.ErrorKind) return nil, errAuthentication } claims.MapClaims[sessionPolicyNameExtracted] = string(spBytes) @@ -339,7 +339,7 @@ func checkRequestAuthTypeWithVID(ctx context.Context, r *http.Request, action po func authenticateRequest(ctx context.Context, r *http.Request, action policy.Action) (s3Err APIErrorCode) { if logger.GetReqInfo(ctx) == nil { - logger.LogIf(ctx, errors.New("unexpected context.Context does not have a logger.ReqInfo"), logger.Minio) + logger.LogIf(ctx, errors.New("unexpected context.Context does not have a logger.ReqInfo"), logger.ErrorKind) return ErrAccessDenied } @@ -378,7 +378,7 @@ func authenticateRequest(ctx context.Context, r *http.Request, action policy.Act // To extract region from XML in request body, get copy of request body. payload, err := io.ReadAll(io.LimitReader(r.Body, maxLocationConstraintSize)) if err != nil { - logger.LogIf(ctx, err, logger.Application) + logger.LogIf(ctx, err, logger.ErrorKind) return ErrMalformedXML } diff --git a/cmd/common-main.go b/cmd/common-main.go index 4722b90b0..e9d00dce2 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -1034,7 +1034,7 @@ func getTLSConfig() (x509Certs []*x509.Certificate, manager *certs.Manager, secu } if err = manager.AddCertificate(certFile, keyFile); err != nil { err = fmt.Errorf("Unable to load TLS certificate '%s,%s': %w", certFile, keyFile, err) - logger.LogIf(GlobalContext, err, logger.Minio) + logger.LogIf(GlobalContext, err, logger.ErrorKind) } } secureConn = true diff --git a/cmd/consolelogger.go b/cmd/consolelogger.go index dacb59e53..5bb50c537 100644 --- a/cmd/consolelogger.go +++ b/cmd/consolelogger.go @@ -196,7 +196,7 @@ func (sys *HTTPConsoleLoggerSys) Send(ctx context.Context, entry interface{}) er sys.logBuf.Value = lg sys.logBuf = sys.logBuf.Next() sys.Unlock() - err := sys.console.Send(entry, string(logger.All)) + err := sys.console.Send(entry) if err != nil { atomic.AddInt64(&sys.failedMessages, 1) } diff --git a/cmd/endpoint.go b/cmd/endpoint.go index 29afe1a64..f2cbb223d 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -530,7 +530,7 @@ func hostResolveToLocalhost(endpoint Endpoint) bool { endpoint.Hostname(), ) ctx := logger.SetReqInfo(GlobalContext, reqInfo) - logger.LogOnceIf(ctx, err, endpoint.Hostname(), logger.Application) + logger.LogOnceIf(ctx, err, endpoint.Hostname(), logger.ErrorKind) return false } var loopback int @@ -602,7 +602,7 @@ func (endpoints Endpoints) UpdateIsLocal() error { ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogOnceIf(ctx, fmt.Errorf("%s resolves to localhost in a containerized deployment, waiting for it to resolve to a valid IP", - endpoints[i].Hostname()), endpoints[i].Hostname(), logger.Application) + endpoints[i].Hostname()), endpoints[i].Hostname(), logger.ErrorKind) } continue @@ -631,7 +631,7 @@ func (endpoints Endpoints) UpdateIsLocal() error { )) ctx := logger.SetReqInfo(GlobalContext, reqInfo) - logger.LogOnceIf(ctx, err, endpoints[i].Hostname(), logger.Application) + logger.LogOnceIf(ctx, err, endpoints[i].Hostname(), logger.ErrorKind) } } else { resolvedList[i] = true @@ -796,7 +796,7 @@ func (p PoolEndpointList) UpdateIsLocal() error { ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogOnceIf(ctx, fmt.Errorf("%s resolves to localhost in a containerized deployment, waiting for it to resolve to a valid IP", - endpoint.Hostname()), endpoint.Hostname(), logger.Application) + endpoint.Hostname()), endpoint.Hostname(), logger.ErrorKind) } continue } @@ -824,7 +824,7 @@ func (p PoolEndpointList) UpdateIsLocal() error { )) ctx := logger.SetReqInfo(GlobalContext, reqInfo) - logger.LogOnceIf(ctx, err, endpoint.Hostname(), logger.Application) + logger.LogOnceIf(ctx, err, endpoint.Hostname(), logger.ErrorKind) } } else { resolvedList[endpoint] = true diff --git a/cmd/erasure-multipart.go b/cmd/erasure-multipart.go index af5c035aa..1f44af1fe 100644 --- a/cmd/erasure-multipart.go +++ b/cmd/erasure-multipart.go @@ -583,7 +583,7 @@ func (er erasureObjects) PutObjectPart(ctx context.Context, bucket, object, uplo data := r.Reader // Validate input data size and it can never be less than zero. if data.Size() < -1 { - logger.LogIf(ctx, errInvalidArgument, logger.Application) + logger.LogIf(ctx, errInvalidArgument, logger.ErrorKind) return pi, toObjectErr(errInvalidArgument) } diff --git a/cmd/erasure-object.go b/cmd/erasure-object.go index 62be68a14..b911846b9 100644 --- a/cmd/erasure-object.go +++ b/cmd/erasure-object.go @@ -1094,7 +1094,7 @@ func (er erasureObjects) putMetacacheObject(ctx context.Context, key string, r * // Validate input data size and it can never be less than zero. if data.Size() < -1 { - logger.LogIf(ctx, errInvalidArgument, logger.Application) + logger.LogIf(ctx, errInvalidArgument, logger.ErrorKind) return ObjectInfo{}, toObjectErr(errInvalidArgument) } @@ -1281,7 +1281,7 @@ func (er erasureObjects) putObject(ctx context.Context, bucket string, object st // Validate input data size and it can never be less than -1. if data.Size() < -1 { - logger.LogIf(ctx, errInvalidArgument, logger.Application) + logger.LogIf(ctx, errInvalidArgument, logger.ErrorKind) return ObjectInfo{}, toObjectErr(errInvalidArgument) } diff --git a/cmd/sts-errors.go b/cmd/sts-errors.go index eea346394..e2e193435 100644 --- a/cmd/sts-errors.go +++ b/cmd/sts-errors.go @@ -40,7 +40,7 @@ func writeSTSErrorResponse(ctx context.Context, w http.ResponseWriter, errCode S } switch errCode { case ErrSTSInternalError, ErrSTSUpstreamError: - logger.LogIf(ctx, err, logger.Minio) + logger.LogIf(ctx, err, logger.ErrorKind) } encodedErrorResponse := encodeResponse(stsErrorResponse) writeResponse(w, stsErr.HTTPStatusCode, encodedErrorResponse, mimeXML) diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 6c38db5ed..39970ccd0 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -99,8 +99,8 @@ func TestMain(m *testing.M) { // Disable printing console messages during tests. color.Output = io.Discard - // Minimum is error logs for testing - logger.MinimumLogLevel = logger.ErrorLvl + // Disable Error logging in testing. + logger.DisableErrorLog = true // Uncomment the following line to see trace logs during unit tests. // logger.AddTarget(console.New()) diff --git a/go.mod b/go.mod index b9252d8e0..7e097b3ea 100644 --- a/go.mod +++ b/go.mod @@ -51,10 +51,10 @@ require ( github.com/minio/dperf v0.5.3 github.com/minio/highwayhash v1.0.2 github.com/minio/kes-go v0.2.0 - github.com/minio/madmin-go/v3 v3.0.40 + github.com/minio/madmin-go/v3 v3.0.43 github.com/minio/minio-go/v7 v7.0.66 github.com/minio/mux v1.9.0 - github.com/minio/pkg/v2 v2.0.8 + github.com/minio/pkg/v2 v2.0.9-0.20240130164631-ac3f1be23e94 github.com/minio/selfupdate v0.6.0 github.com/minio/sha256-simd v1.0.1 github.com/minio/simdjson-go v0.4.5 @@ -80,7 +80,7 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 github.com/rs/cors v1.10.1 github.com/secure-io/sio-go v0.3.1 - github.com/shirou/gopsutil/v3 v3.23.11 + github.com/shirou/gopsutil/v3 v3.24.1 github.com/tidwall/gjson v1.17.0 github.com/tinylib/msgp v1.1.9 github.com/valyala/bytebufferpool v1.0.0 @@ -196,7 +196,7 @@ require ( github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/minio/colorjson v1.0.6 // indirect github.com/minio/filepath v1.0.0 // indirect - github.com/minio/mc v0.0.0-20240111054932-d4305a5bf95e // indirect + github.com/minio/mc v0.0.0-20240129194012-12f446e1de57 // indirect github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/websocket v1.6.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect diff --git a/go.sum b/go.sum index c294f8dde..8a5a9ab4d 100644 --- a/go.sum +++ b/go.sum @@ -443,10 +443,10 @@ github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/minio/kes-go v0.2.0 h1:HA33arq9s3MErbsj3PAXFVfFo4U4yw7lTKQ5kWFrpCA= github.com/minio/kes-go v0.2.0/go.mod h1:VorHLaIYis9/MxAHAtXN4d8PUMNKhIxTIlvFt0hBOEo= -github.com/minio/madmin-go/v3 v3.0.40 h1:e4bfbRYgzv+Sl13ek6CM1la0PMLfxfgmKSLjBBDil0I= -github.com/minio/madmin-go/v3 v3.0.40/go.mod h1:4QN2NftLSV7MdlT50dkrenOMmNVHluxTvlqJou3hte8= -github.com/minio/mc v0.0.0-20240111054932-d4305a5bf95e h1:vKnv5aBTcAAnDGYeJW/SPieXCerp/7MIYxuEUYt7iOE= -github.com/minio/mc v0.0.0-20240111054932-d4305a5bf95e/go.mod h1:wFVJTmLJniMFDkcvPP0h/KvCxK+MiA2rc6q7KUefN28= +github.com/minio/madmin-go/v3 v3.0.43 h1:AkniczVEkBErQ94MikyPINGoOjFWhuP8xH5KmFpAaO0= +github.com/minio/madmin-go/v3 v3.0.43/go.mod h1:ZDF7kf5fhmxLhbGTqyq5efs4ao0v4eWf7nOuef/ljJs= +github.com/minio/mc v0.0.0-20240129194012-12f446e1de57 h1:FO4a9XVuLcIS5s11efycWkBNrfIz4HtDQgUhR+xmLsQ= +github.com/minio/mc v0.0.0-20240129194012-12f446e1de57/go.mod h1:MmDLdb7NWd/OYhcKcXKvwErq2GNa/Zq6xtTWuhdC4II= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= github.com/minio/minio-go/v6 v6.0.46/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg= @@ -454,8 +454,8 @@ github.com/minio/minio-go/v7 v7.0.66 h1:bnTOXOHjOqv/gcMuiVbN9o2ngRItvqE774dG9nq0 github.com/minio/minio-go/v7 v7.0.66/go.mod h1:DHAgmyQEGdW3Cif0UooKOyrT3Vxs82zNdV6tkKhRtbs= github.com/minio/mux v1.9.0 h1:dWafQFyEfGhJvK6AwLOt83bIG5bxKxKJnKMCi0XAaoA= github.com/minio/mux v1.9.0/go.mod h1:1pAare17ZRL5GpmNL+9YmqHoWnLmMZF9C/ioUCfy0BQ= -github.com/minio/pkg/v2 v2.0.8 h1:JuNWjELRaDSMZegeWxNcx5Lf7ZxqKAI5hjSgx1bLbKc= -github.com/minio/pkg/v2 v2.0.8/go.mod h1:yayUTo82b0RK+e97hGb1naC787mOtUEyDs3SIcwSyHI= +github.com/minio/pkg/v2 v2.0.9-0.20240130164631-ac3f1be23e94 h1:nBZkkmq9HPfs2ZUDcRqPahe2js1mvMUR/7cBfW17Jik= +github.com/minio/pkg/v2 v2.0.9-0.20240130164631-ac3f1be23e94/go.mod h1:yayUTo82b0RK+e97hGb1naC787mOtUEyDs3SIcwSyHI= github.com/minio/selfupdate v0.6.0 h1:i76PgT0K5xO9+hjzKcacQtO7+MjJ4JKA8Ak8XQ9DDwU= github.com/minio/selfupdate v0.6.0/go.mod h1:bO02GTIPCMQFTEvE5h4DjYB58bCoZ35XLeBf0buTDdM= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= @@ -606,8 +606,8 @@ github.com/safchain/ethtool v0.3.0/go.mod h1:SA9BwrgyAqNo7M+uaL6IYbxpm5wk3L7Mm6o github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg= github.com/secure-io/sio-go v0.3.1 h1:dNvY9awjabXTYGsTF1PiCySl9Ltofk9GA3VdWlo7rRc= github.com/secure-io/sio-go v0.3.1/go.mod h1:+xbkjDzPjwh4Axd07pRKSNriS9SCiYksWnZqdnfpQxs= -github.com/shirou/gopsutil/v3 v3.23.11 h1:i3jP9NjCPUz7FiZKxlMnODZkdSIp2gnzfrvsu9CuWEQ= -github.com/shirou/gopsutil/v3 v3.23.11/go.mod h1:1FrWgea594Jp7qmjHUUPlJDTPgcsb9mGnXDxavtikzM= +github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI= +github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= diff --git a/internal/crypto/key_test.go b/internal/crypto/key_test.go index 873317a0f..cdc56d953 100644 --- a/internal/crypto/key_test.go +++ b/internal/crypto/key_test.go @@ -49,8 +49,8 @@ var generateKeyTests = []struct { } func TestGenerateKey(t *testing.T) { - defer func(l logger.LogLevel) { logger.MinimumLogLevel = l }(logger.MinimumLogLevel) - logger.MinimumLogLevel = logger.ErrorLvl + defer func(l bool) { logger.DisableErrorLog = l }(logger.DisableErrorLog) + logger.DisableErrorLog = true for i, test := range generateKeyTests { i, test := i, test @@ -75,8 +75,8 @@ var generateIVTests = []struct { } func TestGenerateIV(t *testing.T) { - defer func(l logger.LogLevel) { logger.MinimumLogLevel = l }(logger.MinimumLogLevel) - logger.MinimumLogLevel = logger.ErrorLvl + defer func(l bool) { logger.DisableErrorLog = l }(logger.DisableErrorLog) + logger.DisableErrorLog = true for i, test := range generateIVTests { i, test := i, test diff --git a/internal/crypto/metadata_test.go b/internal/crypto/metadata_test.go index 3951da853..df2ed4764 100644 --- a/internal/crypto/metadata_test.go +++ b/internal/crypto/metadata_test.go @@ -313,8 +313,8 @@ var s3CreateMetadataTests = []struct { } func TestS3CreateMetadata(t *testing.T) { - defer func(l logger.LogLevel) { logger.MinimumLogLevel = l }(logger.MinimumLogLevel) - logger.MinimumLogLevel = logger.ErrorLvl + defer func(l bool) { logger.DisableErrorLog = l }(logger.DisableErrorLog) + logger.DisableErrorLog = true for i, test := range s3CreateMetadataTests { metadata := S3.CreateMetadata(nil, test.KeyID, test.SealedDataKey, test.SealedKey) keyID, kmsKey, sealedKey, err := S3.ParseMetadata(metadata) @@ -358,8 +358,8 @@ var ssecCreateMetadataTests = []struct { } func TestSSECCreateMetadata(t *testing.T) { - defer func(l logger.LogLevel) { logger.MinimumLogLevel = l }(logger.MinimumLogLevel) - logger.MinimumLogLevel = logger.ErrorLvl + defer func(l bool) { logger.DisableErrorLog = l }(logger.DisableErrorLog) + logger.DisableErrorLog = true for i, test := range ssecCreateMetadataTests { metadata := SSEC.CreateMetadata(nil, test.SealedKey) sealedKey, err := SSEC.ParseMetadata(metadata) diff --git a/internal/logger/console.go b/internal/logger/console.go index 96f751bc0..4d8f4940a 100644 --- a/internal/logger/console.go +++ b/internal/logger/console.go @@ -91,7 +91,7 @@ func (f fatalMsg) json(msg string, args ...interface{}) { message = fmt.Sprint(args...) } logJSON, err := json.Marshal(&log.Entry{ - Level: FatalLvl.String(), + Level: FatalKind, Message: message, Time: time.Now().UTC(), Trace: &log.Trace{Message: message, Source: []string{getSource(6)}}, @@ -169,7 +169,7 @@ func (i infoMsg) json(msg string, args ...interface{}) { message = fmt.Sprint(args...) } logJSON, err := json.Marshal(&log.Entry{ - Level: InfoLvl.String(), + Level: InfoKind, Message: message, Time: time.Now().UTC(), }) @@ -201,7 +201,7 @@ func (i errorMsg) json(msg string, args ...interface{}) { message = fmt.Sprint(args...) } logJSON, err := json.Marshal(&log.Entry{ - Level: ErrorLvl.String(), + Level: ErrorKind, Message: message, Time: time.Now().UTC(), Trace: &log.Trace{Message: message, Source: []string{getSource(6)}}, @@ -225,7 +225,7 @@ func (i errorMsg) pretty(msg string, args ...interface{}) { // Error : func Error(msg string, data ...interface{}) { - if MinimumLogLevel > ErrorLvl { + if DisableErrorLog { return } consoleLog(errorm, msg, data...) @@ -233,7 +233,7 @@ func Error(msg string, data ...interface{}) { // Info : func Info(msg string, data ...interface{}) { - if MinimumLogLevel > InfoLvl { + if DisableErrorLog { return } consoleLog(info, msg, data...) diff --git a/internal/logger/logger.go b/internal/logger/logger.go index e5e3abe02..9bcf86847 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -39,22 +39,18 @@ import ( // HighwayHash key for logging in anonymous mode var magicHighwayHash256Key = []byte("\x4b\xe7\x34\xfa\x8e\x23\x8a\xcd\x26\x3e\x83\xe6\xbb\x96\x85\x52\x04\x0f\x93\x5d\xa3\x9f\x44\x14\x97\xe0\x9d\x13\x22\xde\x36\xa0") -// LogLevel type -type LogLevel int8 - // Enumerated level types const ( - InfoLvl LogLevel = iota + 1 - ErrorLvl - FatalLvl - - Application = madmin.LogKindApplication - Minio = madmin.LogKindMinio - All = madmin.LogKindAll + // Log types errors + FatalKind = madmin.LogKindFatal + WarningKind = madmin.LogKindWarning + ErrorKind = madmin.LogKindError + EventKind = madmin.LogKindEvent + InfoKind = madmin.LogKindInfo ) -// MinimumLogLevel holds the minimum logging level to print - info by default -var MinimumLogLevel = InfoLvl +// DisableErrorLog avoids printing error/event/info kind of logs +var DisableErrorLog = false var trimStrings []string @@ -67,18 +63,6 @@ var matchingFuncNames = [...]string{ // add more here .. } -func (level LogLevel) String() string { - switch level { - case InfoLvl: - return "INFO" - case ErrorLvl: - return "ERROR" - case FatalLvl: - return "FATAL" - } - return "" -} - // quietFlag: Hide startup messages if enabled // jsonFlag: Display in JSON format, if enabled var ( @@ -274,12 +258,13 @@ func LogIfNot(ctx context.Context, err error, ignored ...error) { } func errToEntry(ctx context.Context, err error, errKind ...interface{}) log.Entry { - logKind := madmin.LogKindAll + logKind := madmin.LogKindError if len(errKind) > 0 { if ek, ok := errKind[0].(madmin.LogKind); ok { logKind = ek } } + req := GetReqInfo(ctx) if req == nil { @@ -322,8 +307,7 @@ func errToEntry(ctx context.Context, err error, errKind ...interface{}) log.Entr entry := log.Entry{ DeploymentID: deploymentID, - Level: ErrorLvl.String(), - LogKind: logKind, + Level: logKind, RemoteHost: req.RemoteHost, Host: req.Host, RequestID: req.RequestID, @@ -359,7 +343,7 @@ func errToEntry(ctx context.Context, err error, errKind ...interface{}) log.Entr // consoleLogIf prints a detailed error message during // the execution of the server. func consoleLogIf(ctx context.Context, err error, errKind ...interface{}) { - if MinimumLogLevel > ErrorLvl { + if DisableErrorLog { return } @@ -372,7 +356,7 @@ func consoleLogIf(ctx context.Context, err error, errKind ...interface{}) { // logIf prints a detailed error message during // the execution of the server. func logIf(ctx context.Context, err error, errKind ...interface{}) { - if MinimumLogLevel > ErrorLvl { + if DisableErrorLog { return } diff --git a/internal/logger/target/console/console.go b/internal/logger/target/console/console.go index 50ef5f605..21d1c07bc 100644 --- a/internal/logger/target/console/console.go +++ b/internal/logger/target/console/console.go @@ -48,7 +48,7 @@ func (c *Target) String() string { } // Send log message 'e' to console -func (c *Target) Send(e interface{}, logKind string) error { +func (c *Target) Send(e interface{}) error { entry, ok := e.(log.Entry) if !ok { return fmt.Errorf("Uexpected log entry structure %#v", e)