Skip to content

Commit

Permalink
Initialised go logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Newton committed Nov 24, 2017
1 parent e3598f0 commit b8cac5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
27 changes: 21 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/gorilla/mux"
"github.com/jawher/mow.cli"
log "github.com/sirupsen/logrus"
"github.com/Financial-Times/go-logger"
)

const (
Expand All @@ -24,6 +24,13 @@ const (
func main() {
app := cli.App("generic-rw-s3", "A RESTful API for writing data to S3")

appName := app.String(cli.StringOpt{
Name: "app-name",
Value: "factset-uploader",
Desc: "Application name",
EnvVar: "APP_NAME",
})

port := app.String(cli.StringOpt{
Name: "port",
Value: "8080",
Expand Down Expand Up @@ -115,6 +122,13 @@ func main() {
EnvVar: "SRC_CONCURRENT_PROCESSING",
})

logLevel := app.String(cli.StringOpt{
Name: "log-level",
Value: "info",
Desc: "Level of required logging",
EnvVar: "LOG_LEVEL",
})

onlyUpdatesEnabled := app.Bool(cli.BoolOpt{
Name: "only-updates-enabled",
Value: false,
Expand All @@ -134,8 +148,9 @@ func main() {

runServer(*port, *resourcePath, *awsRegion, *bucketName, *bucketPrefix, *wrkSize, qConf, *onlyUpdatesEnabled)
}
log.SetLevel(log.InfoLevel)
log.Infof("Application started with args %s", os.Args)

logger.InitLogger(*appName, *logLevel)
logger.Infof("Application started with args %s", os.Args)
app.Run(os.Args)
}

Expand All @@ -161,7 +176,7 @@ func runServer(port string, resourcePath string, awsRegion string, bucketName st
HTTPClient: hc,
})
if err != nil {
log.Fatalf("Failed to create AWS session: %v", err)
logger.Fatalf("Failed to create AWS session: %v", err)
}
svc := s3.New(sess)

Expand All @@ -177,15 +192,15 @@ func runServer(port string, resourcePath string, awsRegion string, bucketName st

qp := service.NewQProcessor(w)

log.Infof("listening on %v", port)
logger.Infof("listening on %v", port)

if qConf.Topic != "" {
c := consumer.NewConsumer(qConf, qp.ProcessMsg, hc)
go c.Start()
defer c.Stop()
}
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatalf("Unable to start server: %v", err)
logger.Fatalf("Unable to start server: %v", err)
}

}
11 changes: 4 additions & 7 deletions service/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,14 @@ func (w *S3Writer) Write(uuid string, b *[]byte, ct string, tid string) (bool, e
return exists, err
}
if w.onlyUpdatesEnabled {
if exists {
if newHash == 0 {
if exists && newHash == 0 {
logger.WithTransactionID(tid).WithUUID(uuid).Info("Object is identical to the stored record, skipping")
return exists, nil
} else {
hashAsString := strconv.FormatUint(newHash, 10)
params.Metadata["Current-Object-Metadata"] = &hashAsString
}
}
hashAsString := strconv.FormatUint(newHash, 10)
params.Metadata["current-object-metadata"] = &hashAsString
}

resp, err := w.svc.PutObject(params)
if err != nil {
logger.WithTransactionID(tid).WithUUID(uuid).Errorf("Error writing payload to s3, response was %v", resp)
Expand Down Expand Up @@ -369,7 +367,6 @@ func (w *S3Writer) compareObjectToStore(uuid string, b *[]byte, tid string) (boo
metadataMap := hoo.Metadata
var currentHashString string

//TODO what if null?
if hash, ok := metadataMap["Current-Object-Hash"]; ok {
currentHashString = *hash
} else {
Expand Down

0 comments on commit b8cac5d

Please sign in to comment.