Skip to content

Commit ac29c08

Browse files
authored
Simplify logging code via WithField (#272)
1 parent dbad81b commit ac29c08

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ target/
22
captive-core/
33
.soroban/
44
!test.toml
5-
*.sqlite
5+
*.sqlite*

cmd/soroban-rpc/internal/daemon/daemon.go

+16-20
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) *feewindow.FeeWindows
298298

299299
readTxMetaCtx, cancelReadTxMeta := context.WithTimeout(context.Background(), cfg.IngestionTimeout)
300300
defer cancelReadTxMeta()
301-
var initialSeq uint32
302-
var currentSeq uint32
301+
302+
var initialSeq, currentSeq uint32
303303
applicableRange, err := db.GetMigrationLedgerRange(readTxMetaCtx, d.db, cfg.HistoryRetentionWindow)
304304
if err != nil {
305305
d.logger.WithError(err).Fatal("could not get ledger range for migration")
@@ -328,13 +328,11 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) *feewindow.FeeWindows
328328
currentSeq = txMeta.LedgerSequence()
329329
if initialSeq == 0 {
330330
initialSeq = currentSeq
331-
d.logger.WithFields(supportlog.F{
332-
"seq": currentSeq,
333-
}).Info("initializing in-memory store")
331+
d.logger.WithField("seq", currentSeq).
332+
Info("initializing in-memory store")
334333
} else if (currentSeq-initialSeq)%inMemoryInitializationLedgerLogPeriod == 0 {
335-
d.logger.WithFields(supportlog.F{
336-
"seq": currentSeq,
337-
}).Debug("still initializing in-memory store")
334+
d.logger.WithField("seq", currentSeq).
335+
Debug("still initializing in-memory store")
338336
}
339337

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

356354
if currentSeq != 0 {
357-
d.logger.WithFields(supportlog.F{
358-
"seq": currentSeq,
359-
}).Info("finished initializing in-memory store and applying DB data migrations")
355+
d.logger.WithField("seq", currentSeq).
356+
Info("finished initializing in-memory store and applying DB data migrations")
360357
}
361358

362359
return feeWindows
363360
}
364361

365362
func (d *Daemon) Run() {
366-
d.logger.WithFields(supportlog.F{
367-
"addr": d.listener.Addr().String(),
368-
}).Info("starting HTTP server")
363+
d.logger.WithField("addr", d.listener.Addr().String()).Info("starting HTTP server")
369364

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

377372
if d.adminServer != nil {
378-
d.logger.WithFields(supportlog.F{
379-
"addr": d.adminListener.Addr().String(),
380-
}).Info("starting Admin HTTP server")
373+
d.logger.
374+
WithField("addr", d.adminListener.Addr().String()).
375+
Info("starting Admin HTTP server")
381376
panicGroup.Go(func() {
382377
if err := d.adminServer.Serve(d.adminListener); !errors.Is(err, http.ErrServerClosed) {
383378
d.logger.WithError(err).Error("soroban admin server encountered fatal error")
384379
}
385380
})
386381
}
387382

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

0 commit comments

Comments
 (0)