Skip to content

Commit

Permalink
fix: use custom logger for libbpf (#811)
Browse files Browse the repository at this point in the history
The libbpf library used by libbpgo print log in a non json format. So we set our own logger to libbpf to log in json format.

Jira: CHAOSPLT-179
  • Loading branch information
aymericDD committed Nov 15, 2023
1 parent dc3a801 commit f4e712a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ebpf/disk-failure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ func main() {
logger, err = log.NewZapLogger()
must(err)

bpf.SetLoggerCbs(bpf.Callbacks{
Log: func(level int, msg string) {
switch level {
case bpf.LibbpfDebugLevel:
logger.Debug(msg)
case bpf.LibbpfInfoLevel:
logger.Info(msg)
case bpf.LibbpfWarnLevel:
logger.Warn(msg)
default:
logger.Error(msg)
}
},
})

// Create the bpf module
bpfModule, err := bpf.NewModuleFromFile("/usr/local/bin/bpf-disk-failure.bpf.o")
must(err)
Expand Down

0 comments on commit f4e712a

Please sign in to comment.