Skip to content

Commit 58cf3c1

Browse files
authored
Merge pull request #50 from DataDog/pgimalac/log-slog
Use slog logger instead of seelog
2 parents 0057e4d + 12aa6dc commit 58cf3c1

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
module github.com/DataDog/gopsutil
22

3+
go 1.24.0
4+
35
require (
46
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705
5-
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
6-
github.com/go-ole/go-ole v1.2.4 // indirect
77
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4
88
github.com/stretchr/testify v1.3.0
9-
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
9+
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf
10+
)
11+
12+
require (
13+
github.com/davecgh/go-spew v1.1.0 // indirect
14+
github.com/go-ole/go-ole v1.2.4 // indirect
15+
github.com/pmezard/go-difflib v1.0.0 // indirect
1016
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 h1:UUppSQnhf4Yc6xGxSkoQpPhb7RVzuv5Nb1mwJ5VId9s=
22
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
3-
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 h1:kHaBemcxl8o/pQ5VM1c8PVE1PubbNx3mjUr09OqWGCs=
4-
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/fd/NrVaLscBKmPigpZpn5YawRPw+e3Yo=
53
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
64
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
75
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=

process/process_linux.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ package process
66
import (
77
"bufio"
88
"bytes"
9+
"context"
910
"encoding/json"
1011
"errors"
1112
"fmt"
1213
"io/ioutil"
14+
"log/slog"
1315
"os"
1416
"path/filepath"
1517
"strconv"
1618
"strings"
1719
"syscall"
1820
"time"
1921

20-
log "github.com/cihub/seelog"
21-
2222
"github.com/DataDog/gopsutil/cpu"
2323
"github.com/DataDog/gopsutil/host"
2424
"github.com/DataDog/gopsutil/internal/common"
@@ -961,63 +961,63 @@ func AllProcesses() (map[int32]*FilledProcess, error) {
961961
for _, pid := range pids {
962962
p, err := NewProcess(pid)
963963
if err != nil {
964-
log.Debugf("Unable to create new process %d, it may have gone away: %s", pid, err)
964+
slog.Debug("Unable to create new process, it may have gone away", "pid", pid, "error", err)
965965
// Skip the rest of the processing because we have no real process.
966966
continue
967967
}
968968
cmdline, err := p.fillSliceFromCmdline()
969969
if err != nil {
970-
log.Debugf("Unable to read process command line for %d: %s", pid, err)
970+
slog.Debug("Unable to read process command line", "pid", pid, "error", err)
971971
cmdline = []string{}
972972
}
973973
if err := p.fillFromStatus(); err != nil {
974-
log.Debugf("Unable to fill from /proc/%d/status: %s", pid, err)
974+
slog.Debug("Unable to fill from /proc/PID/status", "pid", pid, "error", err)
975975
}
976976
memInfo, memInfoEx, err := p.readFromStatm()
977977
if err != nil {
978-
log.Debugf("Unable to fill from /proc/%d/statm: %s", pid, err)
978+
slog.Debug("Unable to fill from /proc/PID/statm", "pid", pid, "error", err)
979979
memInfo = &MemoryInfoStat{}
980980
memInfoEx = &MemoryInfoExStat{}
981981
}
982982
ioStat, err := p.fillFromIO(user)
983983
if os.IsPermission(err) {
984-
log.Tracef("Unable to access /proc/%d/io, permission denied", pid)
984+
slog.Log(context.Background(), slog.LevelDebug-4, "Unable to access /proc/PID/io, permission denied", "pid", pid)
985985
// Without root permissions we can't read for other processes.
986986
ioStat = &IOCountersStat{}
987987
} else if err != nil {
988-
log.Debugf("Unable to access /proc/%d/io: %s", pid, err)
988+
slog.Debug("Unable to access /proc/PID/io", "pid", pid, "error", err)
989989
ioStat = &IOCountersStat{}
990990
}
991991
ppid, _, t1, createTime, nice, err := p.fillFromStat()
992992
if err != nil {
993-
log.Debugf("Unable to fill from /proc/%d/stat: %s", pid, err)
993+
slog.Debug("Unable to fill from /proc/PID/stat", "pid", pid, "error", err)
994994
t1 = &cpu.TimesStat{}
995995
}
996996
cwd, err := p.fillFromCwd(user)
997997
if os.IsPermission(err) {
998998

999-
log.Tracef("Unable to access /proc/%d/cwd, permission denied", pid)
999+
slog.Log(context.Background(), slog.LevelDebug-4, "Unable to access /proc/PID/cwd, permission denied", "pid", pid)
10001000
cwd = ""
10011001
} else if err != nil {
1002-
log.Debugf("Unable to access /proc/%d/cwd: %s", pid, err)
1002+
slog.Debug("Unable to access /proc/PID/cwd", "pid", pid, "error", err)
10031003
cwd = ""
10041004
}
10051005
exe, err := p.fillFromExe(user)
10061006
if os.IsPermission(err) {
10071007
// Without root permissions we can't read for other processes.
1008-
log.Tracef("Unable to access /proc/%d/exe, permission denied", pid)
1008+
slog.Log(context.Background(), slog.LevelDebug-4, "Unable to access /proc/PID/exe, permission denied", "pid", pid)
10091009
exe = ""
10101010
} else if err != nil {
1011-
log.Debugf("Unable to access /proc/%d/exe: %s", pid, err)
1011+
slog.Debug("Unable to access /proc/PID/exe", "pid", pid, "error", err)
10121012
exe = ""
10131013
}
10141014
openFdCount := int32(-1)
10151015
_, fds, err := p.fillFromfdList(user)
10161016
if os.IsPermission(err) {
10171017
// Without root permissions we can't read for other processes.
1018-
log.Tracef("Unable to access /proc/%d/fd, permission denied", pid)
1018+
slog.Log(context.Background(), slog.LevelDebug-4, "Unable to access /proc/PID/fd, permission denied", "pid", pid)
10191019
} else if err != nil {
1020-
log.Debugf("Unable to access /proc/%d/fd: %s", pid, err)
1020+
slog.Debug("Unable to access /proc/PID/fd", "pid", pid, "error", err)
10211021
} else {
10221022
openFdCount = int32(len(fds))
10231023
}

process/process_linux_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
//go:build linux
12
// +build linux
23

34
package process
45

56
import (
7+
"log/slog"
68
"os"
79
"testing"
810

9-
log "github.com/cihub/seelog"
1011
"github.com/stretchr/testify/assert"
1112
)
1213

@@ -24,7 +25,7 @@ func BenchmarkLinuxAllProcessesOnPostgresProcFS(b *testing.B) {
2425
defer os.Unsetenv("HOST_PROC")
2526

2627
// Disable logging (as it'll be noisy)
27-
log.ReplaceLogger(log.Disabled)
28+
slog.SetDefault(slog.New(slog.DiscardHandler))
2829

2930
b.ReportAllocs()
3031
b.ResetTimer()
@@ -45,7 +46,7 @@ func BenchmarkLinuxAllProcessesOnLocalProcFS(b *testing.B) {
4546
errCount := 0
4647

4748
// Disable logging (as it'll be noisy)
48-
log.ReplaceLogger(log.Disabled)
49+
slog.SetDefault(slog.New(slog.DiscardHandler))
4950

5051
b.ReportAllocs()
5152
b.ResetTimer()

process/process_windows.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package process
@@ -13,10 +14,11 @@ import (
1314
"github.com/StackExchange/wmi"
1415
"github.com/shirou/w32"
1516

17+
"log/slog"
18+
1619
cpu "github.com/DataDog/gopsutil/cpu"
1720
"github.com/DataDog/gopsutil/internal/common"
1821
net "github.com/DataDog/gopsutil/net"
19-
log "github.com/cihub/seelog"
2022
)
2123

2224
const (
@@ -553,7 +555,7 @@ func get_username_for_process(h syscall.Handle) (name string, err error) {
553555
var t syscall.Token
554556
err = syscall.OpenProcessToken(h, syscall.TOKEN_QUERY, &t)
555557
if err != nil {
556-
log.Debugf("Failed to open process token %v", err)
558+
slog.Debug("Failed to open process token", "error", err)
557559
return
558560
}
559561
defer t.Close()

0 commit comments

Comments
 (0)