From b40133a3060602e2a7c769e337d3b9b855e02c82 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 14 Jan 2025 01:54:58 +0000 Subject: [PATCH] std: logging refactor --- std/examples/low-level/consumer/main.go | 8 +++----- std/examples/low-level/producer/main.go | 13 ++++++------- tools/putchunks.go | 3 ++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/std/examples/low-level/consumer/main.go b/std/examples/low-level/consumer/main.go index c45f775..a9d053e 100644 --- a/std/examples/low-level/consumer/main.go +++ b/std/examples/low-level/consumer/main.go @@ -11,13 +11,11 @@ import ( "github.com/named-data/ndnd/std/utils" ) -var logger = log.Default() - func main() { app := engine.NewBasicEngine(engine.NewDefaultFace()) err := app.Start() if err != nil { - logger.Fatal(nil, "Unable to start engine", "err", err) + log.Fatal(nil, "Unable to start engine", "err", err) return } defer app.Stop() @@ -32,7 +30,7 @@ func main() { } interest, err := app.Spec().MakeInterest(name, intCfg, nil, nil) if err != nil { - logger.Error(nil, "Unable to make Interest", "err", err) + log.Error(nil, "Unable to make Interest", "err", err) return } @@ -55,7 +53,7 @@ func main() { ch <- struct{}{} }) if err != nil { - logger.Error(nil, "Unable to send Interest", "err", err) + log.Error(nil, "Unable to send Interest", "err", err) return } diff --git a/std/examples/low-level/producer/main.go b/std/examples/low-level/producer/main.go index 09e3ca7..44c2531 100644 --- a/std/examples/low-level/producer/main.go +++ b/std/examples/low-level/producer/main.go @@ -18,7 +18,6 @@ import ( var app ndn.Engine var pib *sec_pib.SqlitePib -var logger = log.Default() func onInterest(args ndn.InterestHandlerArgs) { interest := args.Interest @@ -40,12 +39,12 @@ func onInterest(args ndn.InterestHandlerArgs) { enc.Wire{content}, signer) if err != nil { - logger.Error(nil, "Unable to encode data", "err", err) + log.Error(nil, "Unable to encode data", "err", err) return } err = args.Reply(data.Wire) if err != nil { - logger.Error(nil, "Unable to reply with data", "err", err) + log.Error(nil, "Unable to reply with data", "err", err) return } fmt.Printf("<< D: %s\n", interest.Name().String()) @@ -57,7 +56,7 @@ func main() { app = engine.NewBasicEngine(engine.NewDefaultFace()) err := app.Start() if err != nil { - logger.Fatal(nil, "Unable to start engine", "err", err) + log.Fatal(nil, "Unable to start engine", "err", err) return } defer app.Stop() @@ -69,12 +68,12 @@ func main() { prefix, _ := enc.NameFromStr("/example/testApp") err = app.AttachHandler(prefix, onInterest) if err != nil { - logger.Error(nil, "Unable to register handler", "err", err) + log.Error(nil, "Unable to register handler", "err", err) return } err = app.RegisterRoute(prefix) if err != nil { - logger.Error(nil, "Unable to register route", "err", err) + log.Error(nil, "Unable to register route", "err", err) return } @@ -82,5 +81,5 @@ func main() { sigChannel := make(chan os.Signal, 1) signal.Notify(sigChannel, os.Interrupt, syscall.SIGTERM) receivedSig := <-sigChannel - logger.Info(nil, "Received signal - exiting", "signal", receivedSig) + log.Info(nil, "Received signal - exiting", "signal", receivedSig) } diff --git a/tools/putchunks.go b/tools/putchunks.go index 372b0eb..558a63a 100644 --- a/tools/putchunks.go +++ b/tools/putchunks.go @@ -99,5 +99,6 @@ func (pc *PutChunks) run() { // wait forever sigchan := make(chan os.Signal, 1) signal.Notify(sigchan, os.Interrupt, syscall.SIGTERM) - <-sigchan + receivedSig := <-sigchan + log.Info(nil, "Received signal - exiting", "signal", receivedSig) }