Skip to content

Commit

Permalink
Avoid using fmt.Printf as it doesn't include the extra logging metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
johnabass committed Nov 3, 2017
1 parent 4416ad7 commit 0705847
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/talaria/talaria.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
Expand Down Expand Up @@ -68,33 +67,30 @@ func talaria(arguments []string) int {
v = viper.New()

logger, webPA, err = server.Initialize(applicationName, arguments, f, v)
infoLog = logging.Info(logger)
errorLog = logging.Error(logger)
)

if err != nil {
fmt.Fprintf(os.Stderr, "Unable to initialize Viper environment: %s\n", err)
errorLog.Log(logging.MessageKey(), "Unable to initialize Viper environment", logging.ErrorKey(), err)
return 1
}

var (
infoLog = logging.Info(logger)
errorLog = logging.Error(logger)
)

//
// Initialize the manager first, as if it fails we don't want to advertise this service
//

health := webPA.Health.NewHealth(logger, devicehealth.Options...)
primaryHandler, manager, err := startDeviceManagement(logger, health, v)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to start device management: %s\n", err)
errorLog.Log(logging.MessageKey(), "Unable to start device management", logging.ErrorKey(), err)
return 1
}

_, talariaServer := webPA.Prepare(logger, health, primaryHandler)
waitGroup, shutdown, err := concurrent.Execute(talariaServer)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to start device manager: %s\n", err)
errorLog.Log(logging.MessageKey(), "Unable to start device manager", logging.ErrorKey(), err)
return 1
}

Expand All @@ -104,20 +100,20 @@ func talaria(arguments []string) int {

serviceOptions, err := service.FromViper(service.Sub(v))
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to read service discovery options: %s\n", err)
errorLog.Log(logging.MessageKey(), "Unable to read service discovery options", logging.ErrorKey(), err)
return 2
}

serviceOptions.Logger = logger
services, err := service.New(serviceOptions)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to initialize service discovery: %s\n", err)
errorLog.Log(logging.MessageKey(), "Unable to initialize service discovery", logging.ErrorKey(), err)
return 2
}

instancer, err := services.NewInstancer()
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to obtain service discovery instancer: %s\n", err)
errorLog.Log(logging.MessageKey(), "Unable to obtain service discovery instancer", logging.ErrorKey(), err)
return 2
}

Expand Down

0 comments on commit 0705847

Please sign in to comment.