From f4aaed9ca526a633909b68353d5da1a82eb15ae7 Mon Sep 17 00:00:00 2001 From: Mikhail Swift Date: Wed, 3 Aug 2022 14:19:44 -0400 Subject: [PATCH] chore: use the same logging everywhere Signed-off-by: Mikhail Swift --- cmd/archivist/main.go | 18 +++++++++++------- internal/metadatastorage/mysqlstore/mysql.go | 8 ++++---- internal/server/server.go | 10 +++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cmd/archivist/main.go b/cmd/archivist/main.go index 76634476..0bde3c2c 100644 --- a/cmd/archivist/main.go +++ b/cmd/archivist/main.go @@ -80,12 +80,12 @@ func main() { cfg := new(config.Config) if err := cfg.Process(); err != nil { - logrus.Fatal(err) + log.FromContext(ctx).Fatal(err) } level, err := logrus.ParseLevel(cfg.LogLevel) if err != nil { - logrus.Fatalf("invalid log level %s", cfg.LogLevel) + log.FromContext(ctx).Fatalf("invalid log level %s", cfg.LogLevel) } logrus.SetLevel(level) @@ -109,10 +109,13 @@ func main() { now = time.Now() fileStore, fileStoreCh, err := initObjectStore(ctx, cfg) if err != nil { - logrus.Fatalf("error initializing storage clients: %+v", err) + log.FromContext(ctx).Fatalf("error initializing storage clients: %+v", err) } mysqlStore, mysqlStoreCh, err := mysqlstore.New(ctx, cfg.SQLStoreConnectionString) + if err != nil { + log.FromContext(ctx).Fatalf("error initializing mysql client: %+v", err) + } log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("completed phase 3: initializing storage clients") // ******************************************************************************** @@ -161,7 +164,7 @@ func main() { gqlListener, err := net.Listen(gqlProto, gqlAddress) if err != nil { - log.FromContext(ctx).Fatalf("unable to start graphql listener: ", err) + log.FromContext(ctx).Fatalf("unable to start graphql listener: %+v", err) } go func() { @@ -202,7 +205,7 @@ func initSpiffeConnection(ctx context.Context, cfg *config.Config) []grpc.Server } source, err := workloadapi.NewX509Source(ctx, workloadOpts...) if err != nil { - logrus.Fatalf("error getting x509 source: %+v", err) + log.FromContext(ctx).Fatalf("error getting x509 source: %+v", err) } opts := []grpc.ServerOption{ grpc.Creds(credentials.NewTLS(tlsconfig.MTLSServerConfig(source, source, authorizer))), @@ -210,9 +213,10 @@ func initSpiffeConnection(ctx context.Context, cfg *config.Config) []grpc.Server svid, err = source.GetX509SVID() if err != nil { - logrus.Fatalf("error getting x509 svid: %+v", err) + log.FromContext(ctx).Fatalf("error getting x509 svid: %+v", err) } - logrus.Infof("SVID: %q", svid.ID) + + log.FromContext(ctx).Infof("SVID: %q", svid.ID) return opts } diff --git a/internal/metadatastorage/mysqlstore/mysql.go b/internal/metadatastorage/mysqlstore/mysql.go index 6f4e2419..591393db 100644 --- a/internal/metadatastorage/mysqlstore/mysql.go +++ b/internal/metadatastorage/mysqlstore/mysql.go @@ -24,7 +24,7 @@ import ( "ariga.io/sqlcomment" "entgo.io/ent/dialect/sql" - "github.com/sirupsen/logrus" + "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/testifysec/archivist-api/pkg/api/archivist" "github.com/testifysec/archivist/ent" "github.com/testifysec/archivist/ent/attestationcollection" @@ -72,13 +72,13 @@ func New(ctx context.Context, connectionstring string) (*Store, <-chan error, er <-ctx.Done() err := client.Close() if err != nil { - logrus.WithContext(ctx).Errorf("error closing database: %+v", err) + log.FromContext(ctx).Errorf("error closing database: %+v", err) } close(errCh) }() if err := client.Schema.Create(ctx); err != nil { - logrus.WithContext(ctx).Fatalf("failed creating schema resources: %v", err) + log.FromContext(ctx).Fatalf("failed creating schema resources: %v", err) } return &Store{ @@ -309,7 +309,7 @@ func (s *Store) Store(ctx context.Context, gitoid string, obj []byte) error { }) if err != nil { - logrus.Errorf("unable to store metadata: %+v", err) + log.FromContext(ctx).Errorf("unable to store metadata: %+v", err) return err } diff --git a/internal/server/server.go b/internal/server/server.go index f7e72d5f..aa7dd9b9 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -20,7 +20,7 @@ import ( "io" "github.com/git-bom/gitbom-go" - "github.com/sirupsen/logrus" + "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/testifysec/archivist-api/pkg/api/archivist" ) @@ -41,7 +41,7 @@ func NewArchivistServer(store MetadataStorer) archivist.ArchivistServer { func (s *archivistServer) GetBySubjectDigest(request *archivist.GetBySubjectDigestRequest, server archivist.Archivist_GetBySubjectDigestServer) error { ctx, cancel := context.WithCancel(server.Context()) defer cancel() - logrus.WithContext(ctx).Printf("retrieving by subject... ") + log.FromContext(ctx).Info("retrieving by subject... ") responses, err := s.store.GetBySubjectDigest(ctx, request) if err != nil { return err @@ -121,19 +121,19 @@ func (s *collectorServer) Store(server archivist.Collector_StoreServer) error { // generate gitbom gb := gitbom.NewSha256GitBom() if err := gb.AddReference(payload, nil); err != nil { - logrus.WithContext(ctx).Errorf("gitbom tag generation failed: %+v", err) + log.FromContext(ctx).Errorf("gitbom tag generation failed: %+v", err) return err } gitoid := gb.Identity() if err := s.metadataStore.Store(ctx, gitoid, payload); err != nil { - logrus.WithContext(ctx).Printf("received error from metadata store: %+v", err) + log.FromContext(ctx).Errorf("received error from metadata store: %+v", err) return err } if s.objectStore != nil { if err := s.objectStore.Store(ctx, gitoid, payload); err != nil { - logrus.WithContext(ctx).Printf("received error from object store: %+v", err) + log.FromContext(ctx).Errorf("received error from object store: %+v", err) return err } }