services: update logs flush after services shutdown

Added sync logs for every service separately to provide the ability to
have a custom logger for each service. This commit makes the code follow
the zap usages rules: `Sync calls the underlying Core's Sync method,
flushing any buffered log entries. Applications should take care to
call Sync before exiting.`

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2024-02-18 15:29:04 +03:00
parent 9b540770cd
commit 5bb7c6b715
8 changed files with 9 additions and 0 deletions

View file

@ -295,6 +295,7 @@ func (s *service) Shutdown() {
s.wallet.Close() s.wallet.Close()
} }
} }
_ = s.log.Sync()
} }
func (s *service) eventLoop() { func (s *service) eventLoop() {

View file

@ -1447,6 +1447,7 @@ func (bc *Blockchain) Close() {
close(bc.stopCh) close(bc.stopCh)
<-bc.runToExitCh <-bc.runToExitCh
bc.addLock.Unlock() bc.addLock.Unlock()
_ = bc.log.Sync()
} }
// AddBlock accepts successive block for the Blockchain, verifies it and // AddBlock accepts successive block for the Blockchain, verifies it and

View file

@ -320,6 +320,8 @@ func (s *Server) Shutdown() {
} }
close(s.quit) close(s.quit)
<-s.relayFin <-s.relayFin
_ = s.log.Sync()
} }
// AddService allows to add a service to be started/stopped by Server. // AddService allows to add a service to be started/stopped by Server.

View file

@ -75,4 +75,5 @@ func (ms *Service) ShutDown() {
ms.log.Error("can't shut service down", zap.String("endpoint", srv.Addr), zap.Error(err)) ms.log.Error("can't shut service down", zap.String("endpoint", srv.Addr), zap.Error(err))
} }
} }
_ = ms.log.Sync()
} }

View file

@ -228,6 +228,7 @@ func (n *Notary) Shutdown() {
close(n.stopCh) close(n.stopCh)
<-n.done <-n.done
n.wallet.Close() n.wallet.Close()
_ = n.Config.Log.Sync()
} }
// IsAuthorized returns whether Notary service currently is authorized to collect // IsAuthorized returns whether Notary service currently is authorized to collect

View file

@ -192,6 +192,7 @@ func (o *Oracle) Shutdown() {
o.ResponseHandler.Shutdown() o.ResponseHandler.Shutdown()
<-o.done <-o.done
o.wallet.Close() o.wallet.Close()
_ = o.Log.Sync()
} }
// Start runs the oracle service in a separate goroutine. // Start runs the oracle service in a separate goroutine.

View file

@ -482,6 +482,7 @@ func (s *Server) Shutdown() {
// Wait for handleSubEvents to finish. // Wait for handleSubEvents to finish.
<-s.subEventsToExitCh <-s.subEventsToExitCh
_ = s.log.Sync()
} }
// SetOracleHandler allows to update oracle handler used by the Server. // SetOracleHandler allows to update oracle handler used by the Server.

View file

@ -77,6 +77,7 @@ func (s *service) Shutdown() {
if s.wallet != nil { if s.wallet != nil {
s.wallet.Close() s.wallet.Close()
} }
_ = s.log.Sync()
} }
func (s *service) signAndSend(r *state.MPTRoot) error { func (s *service) signAndSend(r *state.MPTRoot) error {