From 0a1a189cfab25f00272f043815a94ea25c61e33f Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Wed, 24 Nov 2021 19:32:24 +0100 Subject: [PATCH] refactor(log): use zap logger --- pkg/train/archives.go | 6 +++--- pkg/train/train.go | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/train/archives.go b/pkg/train/archives.go index f633560..00b3b32 100644 --- a/pkg/train/archives.go +++ b/pkg/train/archives.go @@ -8,7 +8,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/cyrilix/robocar-tools/pkg/awsutils" - "log" + "go.uber.org/zap" ) func ListArchives(ctx context.Context, bucket string) error { @@ -31,7 +31,7 @@ func (t Training) UploadArchive(ctx context.Context, archive []byte) error { client := s3.NewFromConfig(t.config) key := aws.String("input/data/train/train.zip") - log.Printf("upload archive to bucket '%s/%s'\n", t.bucketName, *key) + zap.S().Infof("upload archive to bucket '%s/%s'", t.bucketName, *key) _, err := client.PutObject( ctx, &s3.PutObjectInput{ @@ -43,6 +43,6 @@ func (t Training) UploadArchive(ctx context.Context, archive []byte) error { if err != nil { return fmt.Errorf("unable to upload archive: %w", err) } - log.Println("archive uploaded") + zap.S().Info("archive uploaded") return nil } diff --git a/pkg/train/train.go b/pkg/train/train.go index c45c8fa..41f057d 100644 --- a/pkg/train/train.go +++ b/pkg/train/train.go @@ -10,7 +10,7 @@ import ( "github.com/cyrilix/robocar-tools/pkg/awsutils" "github.com/cyrilix/robocar-tools/pkg/data" "github.com/cyrilix/robocar-tools/pkg/models" - "log" + "go.uber.org/zap" "strconv" "time" ) @@ -36,18 +36,19 @@ type Training struct { } func (t *Training) TrainDir(ctx context.Context, jobName, basedir string, imgHeight, imgWidth int, sliceSize int, withFlipImage bool, outputModelFile string, enableSpotTraining bool) error { - log.Printf("run training with data from %s\n", basedir) + l := zap.S() + l.Infof("run training with data from %s", basedir) archive, err := data.BuildArchive(basedir, sliceSize, withFlipImage) if err != nil { return fmt.Errorf("unable to build data archive: %w", err) } - log.Println("") + l.Info("") err = t.UploadArchive(ctx, archive) if err != nil { return fmt.Errorf("unable to upload data arrchive: %w", err) } - log.Println("") + l.Info("") err = t.runTraining( ctx, @@ -162,17 +163,17 @@ func (t *Training) runTraining(ctx context.Context, jobName string, slideSize in }, ) if err != nil { - log.Printf("unable to get status from ob %v: %v\n", jobOutput.TrainingJobArn, err) + l.Infof("unable to get status from ob %v: %v", jobOutput.TrainingJobArn, err) continue } switch status.TrainingJobStatus { case types.TrainingJobStatusInProgress: - log.Printf("job in progress: %v - %v - %v\n", status.TrainingJobStatus, status.SecondaryStatus, *status.SecondaryStatusTransitions[len(status.SecondaryStatusTransitions) - 1].StatusMessage) + l.Infof("job in progress: %v - %v - %v", status.TrainingJobStatus, status.SecondaryStatus, *status.SecondaryStatusTransitions[len(status.SecondaryStatusTransitions) - 1].StatusMessage) continue case types.TrainingJobStatusFailed: - return fmt.Errorf("job %s finished with status %v\n", jobName, status.TrainingJobStatus) + return fmt.Errorf("job %s finished with status %v", jobName, status.TrainingJobStatus) default: - log.Printf("job %s finished with status %v\n", jobName, status.TrainingJobStatus) + l.Infof("job %s finished with status %v", jobName, status.TrainingJobStatus) return nil } }