From 2a5779cdde62d6e87bfd47a9f90be576dabc1e43 Mon Sep 17 00:00:00 2001 From: Sergey Maskalik Date: Mon, 19 Nov 2018 19:05:38 -0800 Subject: [PATCH] Better logging --- go.mod | 6 ++++++ go.sum | 12 ++++++++++++ main.go | 13 ++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 14e3840..7e8a554 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,18 @@ require ( github.com/apex/log v1.1.0 github.com/aws/aws-sdk-go v1.15.76 github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.7.0 github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-isatty v0.0.4 // indirect github.com/pkg/errors v0.8.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.2.2 // indirect + github.com/tj/assert v0.0.0-20171129193455-018094318fb0 // indirect github.com/tj/go v1.8.6 github.com/tj/go-progress v0.0.0-20180508172012-fadc638a53dd + golang.org/x/net v0.0.0-20181114220301-adae6a3d119a // indirect golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8 // indirect + golang.org/x/text v0.3.0 // indirect gopkg.in/alecthomas/kingpin.v2 v2.2.6 ) diff --git a/go.sum b/go.sum index 5f95bea..8654a14 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/aws/aws-sdk-go v1.15.76 h1:AZB4clNWIk13YJaTm07kqyrHkj7gZYBQCgyTh/v4Se github.com/aws/aws-sdk-go v1.15.76/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM= github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37 h1:uxxtrnACqI9zK4ENDMf0WpXfUsHP5V8liuq5QdgDISU= github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE= @@ -18,11 +20,21 @@ github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/tj/assert v0.0.0-20171129193455-018094318fb0 h1:Rw8kxzWo1mr6FSaYXjQELRe88y2KdfynXdnK72rdjtA= +github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0= github.com/tj/go v1.8.6 h1:HZ+XV+wB4vqN5y5VLoZqYUuUJTBF+2kblBru7aUa44E= github.com/tj/go v1.8.6/go.mod h1:iDIwBG1ZkyeGIOBZLZQfpIztHr5m0gG+YGXrKaUC4yE= github.com/tj/go-progress v0.0.0-20180508172012-fadc638a53dd h1:vVcJMsELyu9DdEDBEtFfK5PdAhEK+aYjMg0ZFxc1K4U= github.com/tj/go-progress v0.0.0-20180508172012-fadc638a53dd/go.mod h1:abH8hpo1+c7MbAa0ZCKvvGOgowFNgaoRQEcY0vsRTh4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8 h1:YoY1wS6JYVRpIfFngRf2HHo9R9dAne3xbkGOQ5rJXjU= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= diff --git a/main.go b/main.go index f40122f..4a773ac 100644 --- a/main.go +++ b/main.go @@ -45,7 +45,7 @@ func main() { sess, err := session.NewSession(&aws.Config{Region: aws.String(*region)}) if err != nil { - log.Error(color.New(color.FgRed).Sprintf("Unable to create AWS session for region: ", *region)) + log.Error(color.New(color.FgRed).Sprintf("Unable to create AWS session for region \r\n", *region)) return } @@ -54,7 +54,9 @@ func main() { err, sourceQueueUrl := resolveQueueUrl(svc, *sourceQueue) if err != nil { - log.Error(color.New(color.FgRed).Sprintf("Unable to locate the source queue with name: %s, check region and name", *sourceQueue)) + log.WithError(err).Error(color.New(color.FgRed).Sprintf( + "Unable to locate the source queue with name: %s, check region and name.", + *sourceQueue)) return } @@ -63,7 +65,7 @@ func main() { err, destinationQueueUrl := resolveQueueUrl(svc, *destinationQueue) if err != nil { - log.Error(color.New(color.FgRed).Sprintf("Unable to locate the destination queue with name: %s, check region and name", *sourceQueue)) + log.Error(color.New(color.FgRed).Sprintf("Unable to locate the destination queue with name: %s, check region and name", *destinationQueue)) return } @@ -84,6 +86,11 @@ func main() { log.Info(color.New(color.FgCyan).Sprintf("Approximate number of messages in the source queue: %s", *queueAttributes.Attributes["ApproximateNumberOfMessages"])) + if numberOfMessages == 0 { + log.Info("Looks like nothing to move. Done.") + return + } + moveMessages(sourceQueueUrl, destinationQueueUrl, svc, numberOfMessages) }