Skip to content

Commit e9aa886

Browse files
authored
Switch from go-kit/log to log/slog (#595)
Replacing go-kit/log with log/slog
1 parent 4d23757 commit e9aa886

17 files changed

+341
-115
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ ftpserver
55
debug
66
__debug_bin*
77
*.toml
8-
.opencode/
8+
coverage.txt

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The test suite uses a **reference driver implementation** (`driver_test.go`) wit
7171
## Key Dependencies
7272

7373
- `github.com/spf13/afero`: File system abstraction for driver implementations
74-
- `github.com/fclairamb/go-log`: Logging abstraction supporting multiple frameworks
74+
- `log/slog`: Go standard library structured logging (no external logging dependencies)
7575

7676
## Code Conventions
7777

OpenCode.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ If you're interested in a fully featured FTP server, you should use [sftpgo](htt
2828
* Clean code: No sleep, no panic, no global sync (only around control/transfer connection per client)
2929
* Uses only the standard library except for:
3030
* [afero](https://github.com/spf13/afero) for generic file systems handling
31-
* [fclairamb/go-log](https://github.com/fclairamb/go-log) for logging through your existing libraries [go-kit/log](https://github.com/go-kit/log), [log15](https://github.com/inconshreveable/log15), [zap](https://github.com/uber-go/zap), [zerolog](https://github.com/rs/zerolog/), [logrus](https://github.com/sirupsen/logrus)
31+
* Uses standard library [log/slog](https://pkg.go.dev/log/slog) for structured logging
3232
* Supported extensions:
3333
* [AUTH](https://tools.ietf.org/html/rfc2228#page-6) - Control session protection
3434
* [AUTH TLS](https://tools.ietf.org/html/rfc4217#section-4.1) - TLS session

client_handler.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"log/slog"
89
"net"
910
"strings"
1011
"sync"
1112
"time"
12-
13-
log "github.com/fclairamb/go-log"
1413
)
1514

1615
// HASHAlgo is the enumerable that represents the supported HASH algorithms.
@@ -88,7 +87,7 @@ type clientHandler struct {
8887
clnt string // Identified client
8988
command string // Command received on the connection
9089
ctxRnfr string // Rename from
91-
logger log.Logger // Client handler logging
90+
logger *slog.Logger // Client handler logging
9291
transferWg sync.WaitGroup // wait group for command that open a transfer connection
9392
transfer transferHandler // Transfer connection (passive or active)s
9493
extra any // Additional application-specific data

codecov.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: 87%
6+
patch:
7+
default:
8+
target: 70%

driver_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import (
44
"crypto/tls"
55
"errors"
66
"io"
7+
"log/slog"
78
"net"
89
"os"
910
"strings"
1011
"sync"
1112
"testing"
1213
"time"
1314

14-
log "github.com/fclairamb/go-log"
15-
"github.com/fclairamb/go-log/gokit"
16-
gklog "github.com/go-kit/log"
1715
"github.com/spf13/afero"
1816
"github.com/stretchr/testify/require"
1917
)
@@ -72,14 +70,14 @@ func NewTestServerWithTestDriver(t *testing.T, driver *TestServerDriver) *FtpSer
7270
driver.Init()
7371

7472
// If we are in debug mode, we should log things
75-
var logger log.Logger
73+
var logger *slog.Logger
7674
if driver.Debug {
77-
logger = gokit.NewWrap(gklog.NewLogfmtLogger(gklog.NewSyncWriter(os.Stdout))).With(
78-
"ts", gokit.GKDefaultTimestampUTC,
79-
"caller", gokit.GKDefaultCaller,
80-
)
75+
logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
76+
AddSource: true,
77+
Level: slog.LevelDebug,
78+
}))
8179
} else {
82-
logger = nil
80+
logger = slog.New(slog.NewTextHandler(io.Discard, nil)) //nolint:sloglint // DiscardHandler requires Go 1.23+
8381
}
8482

8583
s := NewTestServerWithDriverAndLogger(t, driver, logger)
@@ -88,7 +86,7 @@ func NewTestServerWithTestDriver(t *testing.T, driver *TestServerDriver) *FtpSer
8886
}
8987

9088
// NewTestServerWithTestDriver provides a server instantiated with some settings
91-
func NewTestServerWithDriverAndLogger(t *testing.T, driver MainDriver, logger log.Logger) *FtpServer {
89+
func NewTestServerWithDriverAndLogger(t *testing.T, driver MainDriver, logger *slog.Logger) *FtpServer {
9290
t.Helper()
9391

9492
server := NewFtpServer(driver)

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ go 1.24.0
55
toolchain go1.25.5
66

77
require (
8-
github.com/fclairamb/go-log v0.6.0
9-
github.com/go-kit/log v0.2.1
108
github.com/secsy/goftp v0.0.0-20200609142545-aa2de14babf4
119
github.com/spf13/afero v1.15.0
1210
github.com/stretchr/testify v1.11.1
@@ -15,7 +13,6 @@ require (
1513

1614
require (
1715
github.com/davecgh/go-spew v1.1.1 // indirect
18-
github.com/go-logfmt/logfmt v0.6.0 // indirect
1916
github.com/pmezard/go-difflib v1.0.0 // indirect
2017
golang.org/x/text v0.28.0 // indirect
2118
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/drakkan/goftp v0.0.0-20201220151643-27b7174e8caf h1:hb1QxC7CuOP25cKVNL5vVU+22w1m1A2ia76o4kt4n60=
44
github.com/drakkan/goftp v0.0.0-20201220151643-27b7174e8caf/go.mod h1:K3yqfa64LwJzUpdUWC6b524HO7U7DmBnrJuBjxKSZOQ=
5-
github.com/fclairamb/go-log v0.5.0 h1:Gz9wSamEaA6lta4IU2cjJc2xSq5sV5VYSB5w/SUHhVc=
6-
github.com/fclairamb/go-log v0.5.0/go.mod h1:XoRO1dYezpsGmLLkZE9I+sHqpqY65p8JA+Vqblb7k40=
7-
github.com/fclairamb/go-log v0.6.0 h1:1V7BJ75P2PvanLHRyGBBFjncB6d4AgEmu+BPWKbMkaU=
8-
github.com/fclairamb/go-log v0.6.0/go.mod h1:cyXxOw4aJwO6lrZb8GRELSw+sxO6wwkLJdsjY5xYCWA=
9-
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
10-
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
11-
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
12-
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
13-
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
14-
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
155
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
166
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17-
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=
18-
github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo=
197
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
208
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
21-
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
22-
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
23-
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
24-
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
259
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
2610
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
27-
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
28-
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
29-
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
30-
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
31-
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
32-
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
33-
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
34-
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
35-
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
36-
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
37-
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
38-
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
3911
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
4012
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
41-
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
42-
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
4313
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
4414
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
4515
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

handle_misc.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ func (c *clientHandler) handleABOR(param string) error {
332332
c.isTransferAborted = true
333333

334334
if err := c.closeTransfer(); err != nil {
335-
c.logger.Warn(
336-
"Problem aborting transfer for command", param,
337-
"err", err,
338-
)
335+
c.logger.Warn("Problem aborting transfer for command", "command", param, "err", err)
339336
}
340337

341338
if c.debug {

0 commit comments

Comments
 (0)