From 1bbda0b3be636884e01d20d03df516c04992db0b Mon Sep 17 00:00:00 2001 From: Viet Anh Duong Date: Sat, 30 Dec 2023 09:46:11 +0000 Subject: [PATCH] Correct log level Signed-off-by: Viet Anh Duong --- module.go | 2 +- pkg/syms/kern_sym.go | 2 +- pkg/syms/proc_module.go | 10 +++++----- pkg/syms/vdso.go | 14 +++++++------- stack_table.go | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/module.go b/module.go index 681aac8..b1e9efc 100644 --- a/module.go +++ b/module.go @@ -321,7 +321,7 @@ func (m *Module) AttachXDP(ifname, prog string, flags uint64) error { if err != nil { return fmt.Errorf("net interface by name: %w", err) } - log.Debugf("found interface %s at index: %d", i.Name, i.Index) + log.Tracef("Found interface %s at index: %d", i.Name, i.Index) l, err := link.AttachXDP(link.XDPOptions{ Program: p, diff --git a/pkg/syms/kern_sym.go b/pkg/syms/kern_sym.go index 6653794..7f45a85 100644 --- a/pkg/syms/kern_sym.go +++ b/pkg/syms/kern_sym.go @@ -28,7 +28,7 @@ func (s *KernSym) Refresh() { } symbols, err := parseKallsyms(s.path) if err != nil { - log.Warnf("KernSym refresh: failed to parse kallsym(path=%s): %v", s.path, err) + log.WithError(err).Warnf("KernSym refresh: failed to parse kallsym(path=%s)", s.path) return } s.symbols = symbols diff --git a/pkg/syms/proc_module.go b/pkg/syms/proc_module.go index 8c9e920..0e8b1f6 100644 --- a/pkg/syms/proc_module.go +++ b/pkg/syms/proc_module.go @@ -110,7 +110,7 @@ func (m *ProcModule) load() { if m.typ == SO || m.typ == EXEC { mf, err := elf.NewMMapedElfFile(m.path.GetPath()) if err != nil { - log.Errorf("Failed to open mmaped file %s: %v", m.path.GetPath(), err) + log.WithError(err).Tracef("Failed to open mmaped file %s", m.path.GetPath()) return } defer mf.Close() @@ -128,7 +128,7 @@ func (m *ProcModule) load() { if debugfile := m.findDebugFile(mf); debugfile != "" { debugmf, err := elf.NewMMapedElfFile(debugfile) if err != nil { - log.Errorf("Failed to open mmaped debug file %s: %v", debugfile, err) + log.WithError(err).Tracef("Failed to open mmaped debug file %s", debugfile) return } defer debugmf.Close() @@ -144,7 +144,7 @@ func (m *ProcModule) load() { var err error m.table, err = buildVDSOResolver() if err != nil { - log.Warnf("Failed to create vDSO resolver: %v", err) + log.WithError(err).Trace("Failed to create vDSO resolver") } } } @@ -203,10 +203,10 @@ func createSymbolTable(mf *elf.MMapedElfFile, opts *elf.SymbolOptions) SymbolTab symtbl, err := mf.NewSymbolTable(opts) if err != nil { - log.WithError(err).Debugf("Failed to create Symbol Table (ELF: %s)", mf.FilePath()) + log.WithError(err).Tracef("Failed to create Symbol Table (ELF: %s)", mf.FilePath()) } if symtbl == nil && gotbl == nil { - log.Errorf("No symbol resolver available for ELF file %s", mf.FilePath()) + log.Warnf("No symbol resolver available for ELF file %s", mf.FilePath()) return &emptyTable{} } if gotbl != nil { diff --git a/pkg/syms/vdso.go b/pkg/syms/vdso.go index f9f2c14..4955e43 100644 --- a/pkg/syms/vdso.go +++ b/pkg/syms/vdso.go @@ -36,7 +36,7 @@ func buildVDSOResolver() (SymbolTable, error) { if err != nil { return nil, fmt.Errorf("open mmaped filed %s: %w, image, err", vstatus.image, err) } - log.Debugf("Loaded vDSO (image=%s)", vstatus.image) + log.Tracef("Loaded vDSO (image=%s)", vstatus.image) return createSymbolTable(mf, &elf.SymbolOptions{ DemangleOpts: DemangleFull.ToOptions(), }), nil @@ -65,30 +65,30 @@ func buildVDSOImage(procmap *proc.Map, pid int) string { procmem := proc.HostProcPath(fmt.Sprintf("%d/mem", pid)) mem, err := os.OpenFile(procmem, os.O_RDONLY, 0) if err != nil { - log.Warnf("Build vDSO Image: Failed to open file %s: %v", procmem, err) + log.WithError(err).Tracef("Build vDSO Image: Failed to open file %s", procmem) return "" } defer mem.Close() if _, err = mem.Seek(int64(procmap.StartAddr), 0); err != nil { - log.Warnf("Build vDSO Image: Failed to seek to address: %v", err) + log.WithError(err).Tracef("Build vDSO Image: Failed to seek to address") return "" } buf := make([]byte, size) if _, err = mem.Read(buf); err != nil { - log.Warnf("Build vDSO Image: Failed read mem: %v", err) + log.WithError(err).Tracef("Build vDSO Image: Failed read mem") return "" } tmpfile, err := os.CreateTemp("", fmt.Sprintf("wbpf_%d_vdso_image_*", pid)) if err != nil { - log.Warnf("Build vDSO Image: Failed to create vsdo temp file: %v", err) + log.WithError(err).Tracef("Build vDSO Image: Failed to create vsdo temp file") return "" } defer tmpfile.Close() if _, err = tmpfile.Write(buf); err != nil { - log.Errorf("failed to write to vDSO image: %v", err) + log.WithError(err).Trace("failed to write to vDSO image") } return tmpfile.Name() } @@ -97,7 +97,7 @@ func (s *vdsoStatus) Cleanup() { if s == nil || s.image == "" { return } - log.Debugf("Remove vDSO image: %s", s.image) + log.Tracef("Remove vDSO image: %s", s.image) os.Remove(s.image) s.err = nil } diff --git a/stack_table.go b/stack_table.go index 1c44eb3..eae0dc3 100644 --- a/stack_table.go +++ b/stack_table.go @@ -46,7 +46,7 @@ func (t *StackTable) GetStackAddr(stackid int64, clear bool) []uint64 { if clear { if err := t.Delete(id); err != nil { - log.Tracef("Failed to delete key 0x%08x: %v", stackid, err) + log.WithError(err).Tracef("Failed to delete key 0x%08x", stackid) return nil } } @@ -58,7 +58,7 @@ func (t *StackTable) ClearStackId(stackid int64) { return } if err := t.Delete(uint32(stackid)); err != nil { - log.Tracef("Failed to delete key 0x%08x: %v", stackid, err) + log.WithError(err).Tracef("Failed to delete key 0x%08x", stackid) } }