Skip to content

Commit

Permalink
Simplify logging code via WithField (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored Aug 27, 2024
1 parent dbad81b commit ac29c08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ target/
captive-core/
.soroban/
!test.toml
*.sqlite
*.sqlite*
36 changes: 16 additions & 20 deletions cmd/soroban-rpc/internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) *feewindow.FeeWindows

readTxMetaCtx, cancelReadTxMeta := context.WithTimeout(context.Background(), cfg.IngestionTimeout)
defer cancelReadTxMeta()
var initialSeq uint32
var currentSeq uint32

var initialSeq, currentSeq uint32
applicableRange, err := db.GetMigrationLedgerRange(readTxMetaCtx, d.db, cfg.HistoryRetentionWindow)
if err != nil {
d.logger.WithError(err).Fatal("could not get ledger range for migration")
Expand Down Expand Up @@ -328,13 +328,11 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) *feewindow.FeeWindows
currentSeq = txMeta.LedgerSequence()
if initialSeq == 0 {
initialSeq = currentSeq
d.logger.WithFields(supportlog.F{
"seq": currentSeq,
}).Info("initializing in-memory store")
d.logger.WithField("seq", currentSeq).
Info("initializing in-memory store")
} else if (currentSeq-initialSeq)%inMemoryInitializationLedgerLogPeriod == 0 {
d.logger.WithFields(supportlog.F{
"seq": currentSeq,
}).Debug("still initializing in-memory store")
d.logger.WithField("seq", currentSeq).
Debug("still initializing in-memory store")
}

if err = feeWindows.IngestFees(txMeta); err != nil {
Expand All @@ -354,18 +352,15 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) *feewindow.FeeWindows
}

if currentSeq != 0 {
d.logger.WithFields(supportlog.F{
"seq": currentSeq,
}).Info("finished initializing in-memory store and applying DB data migrations")
d.logger.WithField("seq", currentSeq).
Info("finished initializing in-memory store and applying DB data migrations")
}

return feeWindows
}

func (d *Daemon) Run() {
d.logger.WithFields(supportlog.F{
"addr": d.listener.Addr().String(),
}).Info("starting HTTP server")
d.logger.WithField("addr", d.listener.Addr().String()).Info("starting HTTP server")

panicGroup := util.UnrecoverablePanicGroup.Log(d.logger)
panicGroup.Go(func() {
Expand All @@ -375,19 +370,20 @@ func (d *Daemon) Run() {
})

if d.adminServer != nil {
d.logger.WithFields(supportlog.F{
"addr": d.adminListener.Addr().String(),
}).Info("starting Admin HTTP server")
d.logger.
WithField("addr", d.adminListener.Addr().String()).
Info("starting Admin HTTP server")
panicGroup.Go(func() {
if err := d.adminServer.Serve(d.adminListener); !errors.Is(err, http.ErrServerClosed) {
d.logger.WithError(err).Error("soroban admin server encountered fatal error")
}
})
}

// Shutdown gracefully when we receive an interrupt signal.
// First server.Shutdown closes all open listeners, then closes all idle connections.
// Finally, it waits a grace period (10s here) for connections to return to idle and then shut down.
// Shutdown gracefully when we receive an interrupt signal. First
// server.Shutdown closes all open listeners, then closes all idle
// connections. Finally, it waits a grace period (10s here) for connections
// to return to idle and then shut down.
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)

Expand Down

0 comments on commit ac29c08

Please sign in to comment.