Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Logger Fatal method returns no value #1728

Merged
merged 7 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions cmd/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,54 +61,54 @@ func main() {
// Create auth service configurations
cfg := config{}
if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s configuration : %s", svcName, err.Error())
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(fmt.Sprintf("failed to init logger: %s", err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logger or log?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a native Go log because logger was not initialized properly. But let me also rename it because we have:

logger, err := logger.New(os.Stdout, cfg.LogLevel)

}

// Create new postgres client
dbConfig := pgClient.Config{Name: defDB}
db, err := pgClient.SetupWithConfig(envPrefix, *authPg.Migration(), dbConfig)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to setup postgres database : %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to setup postgres database : %s", err))
}
defer db.Close()

// Create new tracer for database
dbTracer, dbCloser, err := jaegerClient.NewTracer("auth_db", cfg.JaegerURL)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err))
}
defer dbCloser.Close()

// Create new keto reader grpc client
readerConn, _, err := grpcClient.Connect(grpcClient.Config{ClientTLS: false, URL: fmt.Sprintf("%s:%s", cfg.KetoReadHost, cfg.KetoReadPort)})
if err != nil {
logger.Fatal(fmt.Sprintf("failed to connect to keto gRPC: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to connect to keto gRPC: %s", err))
}

// Create new keto writer grpc client
writerConn, _, err := grpcClient.Connect(grpcClient.Config{ClientTLS: false, URL: fmt.Sprintf("%s:%s", cfg.KetoWriteHost, cfg.KetoWritePort)})
if err != nil {
logger.Fatal(fmt.Sprintf("failed to connect to keto gRPC: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to connect to keto gRPC: %s", err))
}

svc := newService(db, dbTracer, cfg.Secret, logger, readerConn, writerConn, cfg.LoginDuration)

// Create new HTTP Server
tracer, closer, err := jaegerClient.NewTracer("auth", cfg.JaegerURL)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err))
}
defer closer.Close()

httpServerConfig := server.Config{Port: defSvcHttpPort}

if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svc, tracer, logger), logger)
Expand All @@ -117,7 +117,7 @@ func main() {
grpcServerConfig := server.Config{Port: defSvcGrpcPort}

if err := env.Parse(&grpcServerConfig, env.Options{Prefix: envPrefixGrpc, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s gRPC server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s gRPC server configuration : %s", svcName, err))
}
registerAuthServiceServer := func(srv *grpc.Server) {
mainflux.RegisterAuthServiceServer(srv, grpcapi.NewServer(tracer, svc))
Expand Down
14 changes: 7 additions & 7 deletions cmd/bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,34 @@ func main() {

cfg := config{}
if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s configuration : %s", svcName, err.Error())
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatal(err.Error())
log.Fatal(fmt.Sprintf("failed to init logger: %s", err))
}

// Create new postgres client
dbConfig := pgClient.Config{Name: defDB}

db, err := pgClient.SetupWithConfig(envPrefix, *bootstrapPg.Migration(), dbConfig)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer db.Close()

// Create new redis client for bootstrap event store
esClient, err := redisClient.Setup(envPrefixES)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to setup %s bootstrap event store redis client : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to setup %s bootstrap event store redis client : %s", svcName, err))
}
defer esClient.Close()

// Create new auth grpc client api
auth, authHandler, err := authClient.Setup(envPrefix, cfg.JaegerURL)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer authHandler.Close()
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
Expand All @@ -89,7 +89,7 @@ func main() {
// Create an new HTTP server
httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger), logger)

Expand All @@ -104,7 +104,7 @@ func main() {
// Subscribe to things event store
thingsESClient, err := redisClient.Setup(envPrefixES)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer thingsESClient.Close()

Expand Down
10 changes: 5 additions & 5 deletions cmd/cassandra-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
cfg := config{}

if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s service configuration : %s", svcName, err.Error())
log.Fatalf("failed to load %s service configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
Expand All @@ -55,23 +55,23 @@ func main() {
// Create new thing grpc client
tc, tcHandler, err := thingsClient.Setup(envPrefix, cfg.JaegerURL)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

// Create new auth grpc client
auth, authHandler, err := authClient.Setup(envPrefix, cfg.JaegerURL)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer authHandler.Close()
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())

// Create new cassandra client
csdSession, err := cassandraClient.Setup(envPrefix)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer csdSession.Close()

Expand All @@ -82,7 +82,7 @@ func main() {
httpServerConfig := server.Config{Port: defSvcHttpPort}

if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, logger), logger)
Expand Down
11 changes: 5 additions & 6 deletions cmd/cassandra-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,19 @@ func main() {

// Create new cassandra writer service configurations
cfg := config{}

if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s service configuration : %s", svcName, err.Error())
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(fmt.Sprintf("failed to init logger: %s", err))
}

// Create new to cassandra client
csdSession, err := cassandraClient.SetupDB(envPrefix, cassandra.Table)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer csdSession.Close()

Expand All @@ -65,7 +64,7 @@ func main() {
// Create new pub sub broker
pubSub, err := brokers.NewPubSub(cfg.BrokerURL, "", logger)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to connect to message broker: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to connect to message broker: %s", err))
}
defer pubSub.Close()

Expand All @@ -78,7 +77,7 @@ func main() {
httpServerConfig := server.Config{Port: defSvcHttpPort}

if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefix, AltPrefix: envPrefixHttp}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName), logger)
Expand Down
16 changes: 8 additions & 8 deletions cmd/certs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func main() {

cfg := config{}
if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s configuration : %s", svcName, err.Error())
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(fmt.Sprintf("failed to init logger: %s", err))
}

tlsCert, caCert, err := loadCertificates(cfg, logger)
Expand All @@ -85,24 +85,24 @@ func main() {
}

if cfg.PkiHost == "" {
logger.Fatal("No host specified for PKI engine")()
logger.Fatal("No host specified for PKI engine")
}

pkiClient, err := vault.NewVaultClient(cfg.PkiToken, cfg.PkiHost, cfg.PkiPath, cfg.PkiRole)
if err != nil {
logger.Fatal("failed to configure client for PKI engine")()
logger.Fatal("failed to configure client for PKI engine")
}

dbConfig := pgClient.Config{Name: defDB}
db, err := pgClient.SetupWithConfig(envPrefix, *certsPg.Migration(), dbConfig)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer db.Close()

auth, authHandler, err := authClient.Setup(envPrefix, cfg.JaegerURL)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer authHandler.Close()
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
Expand All @@ -111,7 +111,7 @@ func main() {

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger), logger)

Expand Down Expand Up @@ -170,7 +170,7 @@ func loadCertificates(conf config, logger logger.Logger) (tls.Certificate, *x509

block, _ := pem.Decode(b)
if block == nil {
logger.Fatal("No PEM data found, failed to decode CA")()
logger.Fatal("No PEM data found, failed to decode CA")
}

caCert, err = x509.ParseCertificate(block.Bytes)
Expand Down
12 changes: 6 additions & 6 deletions cmd/coap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ func main() {

cfg := config{}
if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s configuration : %s", svcName, err.Error())
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(fmt.Sprintf("failed to init logger: %s", err))
}

tc, tcHandler, err := thingsClient.Setup(envPrefix, cfg.JaegerURL)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

nps, err := brokers.NewPubSub(cfg.BrokerURL, "", logger)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to connect to message broker: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to connect to message broker: %s", err))
}
defer nps.Close()

Expand All @@ -73,13 +73,13 @@ func main() {

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHTTPHandler(), logger)

coapServerConfig := server.Config{Port: defSvcCoapPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixCoap, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s CoAP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s CoAP server configuration : %s", svcName, err))
}
cs := coapserver.New(ctx, cancel, svcName, coapServerConfig, api.MakeCoAPHandler(svc, logger), logger)

Expand Down
12 changes: 6 additions & 6 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,38 @@ func main() {

cfg := config{}
if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s service configuration : %s", svcName, err.Error())
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(fmt.Sprintf("failed to init logger: %s", err))
}

tc, tcHandler, err := thingsClient.Setup(envPrefix, cfg.JaegerURL)
if err != nil {
logger.Fatal(err.Error())()
logger.Fatal(err.Error())
}
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

pub, err := brokers.NewPublisher(cfg.BrokerURL)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to connect to message broker: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to connect to message broker: %s", err))
}
defer pub.Close()

svc := newService(pub, tc, logger)

tracer, closer, err := jaegerClient.NewTracer("http_adapter", cfg.JaegerURL)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err.Error()))()
logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err))
}
defer closer.Close()

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error()))()
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, tracer, logger), logger)

Expand Down
Loading