Skip to content

Commit

Permalink
std: logging refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jan 14, 2025
1 parent 00872b2 commit b40133a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 3 additions & 5 deletions std/examples/low-level/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
13 changes: 6 additions & 7 deletions std/examples/low-level/producer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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()
Expand All @@ -69,18 +68,18 @@ 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
}

fmt.Print("Start serving ...")
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)
}
3 changes: 2 additions & 1 deletion tools/putchunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit b40133a

Please sign in to comment.