Skip to content

Commit

Permalink
feat: log output minor optimization (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
brucexc authored Nov 18, 2024
1 parent 411dd54 commit 9576ad6
Show file tree
Hide file tree
Showing 72 changed files with 657 additions and 2,381 deletions.
16 changes: 6 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ var command = cobra.Command{
}
}

zap.L().Info("logger initialized", zap.String("environment", environment))
zap.L().Info("starting RSS3 Node",
zap.String("version", constant.BuildVersion()),
zap.String("environment", environment))

if err = config.HasOneWorker(configFile); err != nil {
return err
Expand Down Expand Up @@ -212,8 +214,6 @@ var command = cobra.Command{
if err := tx.Commit(); err != nil {
return fmt.Errorf("commit transaction: %w", err)
}

zap.L().Info("database transaction committed successfully")
}

switch module {
Expand Down Expand Up @@ -270,7 +270,7 @@ func runCoreService(ctx context.Context, configFile *config.File, databaseClient
if !config.IsRSSComponentOnly(configFile) {
go func() {
if err := node.CheckParams(checkCtx, redisClient, networkParamsCaller, settlementCaller); err != nil {
fmt.Printf("Error checking parameters: %v\n", err)
zap.L().Error("error checking parameters", zap.Error(err))
}
}()
}
Expand All @@ -288,7 +288,6 @@ func runCoreService(ctx context.Context, configFile *config.File, databaseClient
select {
case sig := <-stopChan:
zap.L().Info("shutdown signal received", zap.String("signal", sig.String()))
fmt.Printf("Shutdown signal received: %v.\n", sig)
case err := <-apiErrChan:
zap.L().Error("core service encountered an error", zap.Error(err))
cancel() // signal all goroutines to stop on error
Expand All @@ -304,13 +303,10 @@ func runCoreService(ctx context.Context, configFile *config.File, databaseClient

// findModuleByID find and returns the specified worker ID in all components.
func findModuleByID(configFile *config.File, workerID string) (*config.Module, error) {
zap.L().Debug("searching for module", zap.String("workerID", workerID))

// find the module in a specific component list
findInComponent := func(components []*config.Module) (*config.Module, bool) {
for _, module := range components {
if strings.EqualFold(module.ID, workerID) {
zap.L().Debug("module found", zap.String("moduleID", module.ID))
return module, true
}
}
Expand Down Expand Up @@ -424,7 +420,7 @@ func setOpenTelemetry(config *config.File) error {
}()
}

zap.L().Debug("OpenTelemetry setup completed")
zap.L().Debug("openTelemetry setup completed")

return nil
}
Expand Down Expand Up @@ -453,7 +449,7 @@ func initializePyroscope() {
ProfileTypes: append(pyroscope.DefaultProfileTypes, pyroscope.ProfileGoroutines),
})
} else {
zap.L().Debug("Pyroscope endpoint not configured, skipping initialization")
zap.L().Debug("pyroscope endpoint not configured, skipping initialization")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func _Setup(configName, configType string, v *viper.Viper) (*File, error) {
v.AddConfigPath(path.Join(currentDir, "deploy"))
zap.L().Debug("added current directory config paths", zap.String("currentDir", currentDir))
} else {
zap.L().Warn("failed to get current directory", zap.Error(err))
zap.L().Error("failed to get current directory", zap.Error(err))
}

v.SetEnvPrefix(EnvPrefix)
Expand Down
2 changes: 0 additions & 2 deletions internal/database/dialer/postgres/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ func (c *client) WithTransaction(ctx context.Context, transactionFunction func(c
return fmt.Errorf("begin transaction: %w", err)
}

zap.L().Debug("transaction began successfully")

if err := transactionFunction(ctx, transaction); err != nil {
_ = transaction.Rollback()

Expand Down
Loading

0 comments on commit 9576ad6

Please sign in to comment.