refactor(log): use zap logger

This commit is contained in:
Cyrille Nofficial 2021-11-24 19:32:24 +01:00
parent 456f327788
commit 0a1a189cfa
2 changed files with 12 additions and 11 deletions

View File

@ -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
}

View File

@ -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
}
}