From 49a900554f07b2cf19f1a6f3aa5a69dcb5bf5969 Mon Sep 17 00:00:00 2001 From: Nikhil Ranjan Date: Tue, 24 Sep 2019 13:37:21 +0000 Subject: [PATCH] =?UTF-8?q?MM-18256=20Converting=20to=20structured=20loggi?= =?UTF-8?q?ng=20the=20file=20utils/licen=E2=80=A6=20(#12094)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/license.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/utils/license.go b/utils/license.go index d62e90fd40..9758ca1e0e 100644 --- a/utils/license.go +++ b/utils/license.go @@ -10,7 +10,6 @@ import ( "crypto/x509" "encoding/base64" "encoding/pem" - "fmt" "io/ioutil" "os" "path/filepath" @@ -37,7 +36,7 @@ func ValidateLicense(signed []byte) (bool, string) { _, err := base64.StdEncoding.Decode(decoded, signed) if err != nil { - mlog.Error(fmt.Sprintf("Encountered error decoding license, err=%v", err.Error())) + mlog.Error("Encountered error decoding license", mlog.Err(err)) return false, "" } @@ -58,7 +57,7 @@ func ValidateLicense(signed []byte) (bool, string) { public, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { - mlog.Error(fmt.Sprintf("Encountered error signing license, err=%v", err.Error())) + mlog.Error("Encountered error signing license", mlog.Err(err)) return false, "" } @@ -70,7 +69,7 @@ func ValidateLicense(signed []byte) (bool, string) { err = rsa.VerifyPKCS1v15(rsaPublic, crypto.SHA512, d, signature) if err != nil { - mlog.Error(fmt.Sprintf("Invalid signature, err=%v", err.Error())) + mlog.Error("Invalid signature", mlog.Err(err)) return false, "" } @@ -81,15 +80,15 @@ func GetAndValidateLicenseFileFromDisk(location string) (*model.License, []byte) fileName := GetLicenseFileLocation(location) if _, err := os.Stat(fileName); err != nil { - mlog.Debug(fmt.Sprintf("We could not find the license key in the database or on disk at %v", fileName)) + mlog.Debug("We could not find the license key in the database or on disk at", mlog.String("filename", fileName)) return nil, nil } - mlog.Info(fmt.Sprintf("License key has not been uploaded. Loading license key from disk at %v", fileName)) + mlog.Info("License key has not been uploaded. Loading license key from disk at", mlog.String("filename", fileName)) licenseBytes := GetLicenseFileFromDisk(fileName) if success, licenseStr := ValidateLicense(licenseBytes); !success { - mlog.Error(fmt.Sprintf("Found license key at %v but it appears to be invalid.", fileName)) + mlog.Error("Found license key at %v but it appears to be invalid.", mlog.String("filename", fileName)) return nil, nil } else { return model.LicenseFromJson(strings.NewReader(licenseStr)), licenseBytes @@ -99,14 +98,14 @@ func GetAndValidateLicenseFileFromDisk(location string) (*model.License, []byte) func GetLicenseFileFromDisk(fileName string) []byte { file, err := os.Open(fileName) if err != nil { - mlog.Error(fmt.Sprintf("Failed to open license key from disk at %v err=%v", fileName, err.Error())) + mlog.Error("Failed to open license key from disk at", mlog.String("filename", fileName), mlog.Err(err)) return nil } defer file.Close() licenseBytes, err := ioutil.ReadAll(file) if err != nil { - mlog.Error(fmt.Sprintf("Failed to read license key from disk at %v err=%v", fileName, err.Error())) + mlog.Error("Failed to read license key from disk at", mlog.String("filename", fileName), mlog.Err(err)) return nil }