Skip to content

Commit b04533a

Browse files
committed
refactor: explicit slog integration via slog.SetDefault()
update to go-log v2.8.3-0.20251105220843-b453280b0ce2 which changes GOLOG_CAPTURE_DEFAULT_SLOG to opt-in (default=false). kubo now explicitly calls slog.SetDefault(slog.New(logging.SlogHandler())) to integrate slog with go-log's formatting and level control. changes: - cmd/ipfs/kubo/start.go: add slog.SetDefault() call for application-wide slog integration, maintaining existing gologshim.SetDefaultHandler() for go-libp2p subsystem attribution - docs/environment-variables.md: remove GOLOG_LOG_LABELS and GOLOG_CAPTURE_DEFAULT_SLOG sections (no longer relevant to kubo users) - go.mod: update go-log to b453280b0ce2 while automatic slog.Default() capture was convenient, go-libp2p chose to require explicit gologshim registration for clarity. for consistency, we now do the same for slog.Default() - making both integration points explicit rather than mixing automatic and manual approaches. references: - ipfs/go-log#176 (comment) - ipfs/go-log@b453280
1 parent ef7d8d1 commit b04533a

File tree

8 files changed

+16
-68
lines changed

8 files changed

+16
-68
lines changed

cmd/ipfs/kubo/start.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11+
"log/slog"
1112
"net"
1213
"net/http"
1314
"os"
@@ -52,12 +53,13 @@ var (
5253
)
5354

5455
func init() {
56+
// Set go-log's slog handler as the application-wide default.
57+
// This ensures all slog-based logging uses go-log's formatting.
58+
slog.SetDefault(slog.New(logging.SlogHandler()))
59+
5560
// Wire go-log's slog bridge to go-libp2p's gologshim.
56-
// This ensures go-libp2p logs integrate with go-log's formatting
57-
// and dynamic level control (e.g., `ipfs log level libp2p-swarm debug`).
58-
//
59-
// Use SlogHandler() to get go-log's bridge directly.
60-
// This works even when GOLOG_CAPTURE_DEFAULT_SLOG=false.
61+
// This provides go-libp2p loggers with the "logger" attribute
62+
// for per-subsystem level control (e.g., `ipfs log level libp2p-swarm debug`).
6163
gologshim.SetDefaultHandler(logging.SlogHandler())
6264
}
6365

docs/environment-variables.md

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -102,60 +102,6 @@ When stderr and/or stdout options are configured or specified by the `GOLOG_OUTP
102102
- `GOLOG_OUTPUT="stdout"` logs only to stdout
103103
- `GOLOG_OUTPUT="stderr+stdout"` logs to both stderr and stdout
104104

105-
## `GOLOG_LOG_LABELS`
106-
107-
Adds static key-value labels to all log entries. Labels are specified as comma-separated `key=value` pairs.
108-
109-
This is useful for:
110-
- Identifying logs from different instances in aggregated logging systems
111-
- Adding deployment context (datacenter, environment, version)
112-
- Correlating logs across distributed systems
113-
114-
Example:
115-
116-
```console
117-
export GOLOG_LOG_LABELS="app=kubo,dc=us-west-1,instance=node-42"
118-
ipfs daemon
119-
```
120-
121-
Each log entry will include these labels in JSON format:
122-
123-
```json
124-
{
125-
"level": "info",
126-
"ts": "2025-01-05T10:30:00.000Z",
127-
"logger": "core",
128-
"msg": "daemon started",
129-
"app": "kubo",
130-
"dc": "us-west-1",
131-
"instance": "node-42"
132-
}
133-
```
134-
135-
## `GOLOG_CAPTURE_DEFAULT_SLOG`
136-
137-
Controls whether go-log installs its bridge as Go's default slog handler via `slog.SetDefault()`.
138-
139-
When enabled (default), go-log captures logs from:
140-
- Go standard library packages using `log/slog`
141-
- Third-party libraries using `log/slog`
142-
- go-libp2p (which uses slog internally via gologshim)
143-
144-
This allows unified log management where `ipfs log level` commands control both Kubo subsystems and go-libp2p loggers.
145-
146-
To disable the slog bridge:
147-
148-
```console
149-
export GOLOG_CAPTURE_DEFAULT_SLOG="false"
150-
ipfs daemon
151-
```
152-
153-
When disabled, only native go-log loggers will be captured. Libraries using `log/slog` directly will use Go's default handler and won't appear in `ipfs log tail` or respond to `ipfs log level` commands.
154-
155-
Default: `true` (enabled)
156-
157-
For more details, see [go-log's slog integration documentation](https://github.com/ipfs/go-log/blob/master/README.md#slog-integration).
158-
159105
## `GOLOG_TRACING_FILE`
160106

161107
Sets the file to which Kubo sends tracing events. By default, tracing is

docs/examples/kubo-as-a-library/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/ipfs/go-ipld-format v0.6.3 // indirect
9494
github.com/ipfs/go-ipld-git v0.1.1 // indirect
9595
github.com/ipfs/go-ipld-legacy v0.2.2 // indirect
96-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a // indirect
96+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2 // indirect
9797
github.com/ipfs/go-metrics-interface v0.3.0 // indirect
9898
github.com/ipfs/go-peertaskqueue v0.8.2 // indirect
9999
github.com/ipfs/go-test v0.2.3 // indirect

docs/examples/kubo-as-a-library/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ github.com/ipfs/go-ipld-git v0.1.1/go.mod h1:+VyMqF5lMcJh4rwEppV0e6g4nCCHXThLYYD
349349
github.com/ipfs/go-ipld-legacy v0.2.2 h1:DThbqCPVLpWBcGtU23KDLiY2YRZZnTkXQyfz8aOfBkQ=
350350
github.com/ipfs/go-ipld-legacy v0.2.2/go.mod h1:hhkj+b3kG9b2BcUNw8IFYAsfeNo8E3U7eYlWeAOPyDU=
351351
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
352-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a h1:ZtrWQty1MnTu5sJFWpX01KIAEgqmyVphKTmdIbuspm0=
353-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
352+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2 h1:YEH65nXkYTyK4FIIess2VXnPIfioCGABxz4nLgFbyKg=
353+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
354354
github.com/ipfs/go-metrics-interface v0.3.0 h1:YwG7/Cy4R94mYDUuwsBfeziJCVm9pBMJ6q/JR9V40TU=
355355
github.com/ipfs/go-metrics-interface v0.3.0/go.mod h1:OxxQjZDGocXVdyTPocns6cOLwHieqej/jos7H4POwoY=
356356
github.com/ipfs/go-peertaskqueue v0.8.2 h1:PaHFRaVFdxQk1Qo3OKiHPYjmmusQy7gKQUaL8JDszAU=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ require (
3939
github.com/ipfs/go-ipld-format v0.6.3
4040
github.com/ipfs/go-ipld-git v0.1.1
4141
github.com/ipfs/go-ipld-legacy v0.2.2
42-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a
42+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2
4343
github.com/ipfs/go-metrics-interface v0.3.0
4444
github.com/ipfs/go-metrics-prometheus v0.1.0
4545
github.com/ipfs/go-test v0.2.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ github.com/ipfs/go-ipld-git v0.1.1/go.mod h1:+VyMqF5lMcJh4rwEppV0e6g4nCCHXThLYYD
416416
github.com/ipfs/go-ipld-legacy v0.2.2 h1:DThbqCPVLpWBcGtU23KDLiY2YRZZnTkXQyfz8aOfBkQ=
417417
github.com/ipfs/go-ipld-legacy v0.2.2/go.mod h1:hhkj+b3kG9b2BcUNw8IFYAsfeNo8E3U7eYlWeAOPyDU=
418418
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
419-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a h1:ZtrWQty1MnTu5sJFWpX01KIAEgqmyVphKTmdIbuspm0=
420-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
419+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2 h1:YEH65nXkYTyK4FIIess2VXnPIfioCGABxz4nLgFbyKg=
420+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
421421
github.com/ipfs/go-metrics-interface v0.3.0 h1:YwG7/Cy4R94mYDUuwsBfeziJCVm9pBMJ6q/JR9V40TU=
422422
github.com/ipfs/go-metrics-interface v0.3.0/go.mod h1:OxxQjZDGocXVdyTPocns6cOLwHieqej/jos7H4POwoY=
423423
github.com/ipfs/go-metrics-prometheus v0.1.0 h1:bApWOHkrH3VTBHzTHrZSfq4n4weOZDzZFxUXv+HyKcA=

test/dependencies/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd
99
github.com/golangci/golangci-lint v1.64.8
1010
github.com/ipfs/go-cidutil v0.1.0
11-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a
11+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2
1212
github.com/ipfs/go-test v0.2.3
1313
github.com/ipfs/hang-fds v0.1.0
1414
github.com/ipfs/iptb v1.4.1

test/dependencies/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ github.com/ipfs/go-ipld-format v0.6.3 h1:9/lurLDTotJpZSuL++gh3sTdmcFhVkCwsgx2+rA
364364
github.com/ipfs/go-ipld-format v0.6.3/go.mod h1:74ilVN12NXVMIV+SrBAyC05UJRk0jVvGqdmrcYZvCBk=
365365
github.com/ipfs/go-ipld-legacy v0.2.2 h1:DThbqCPVLpWBcGtU23KDLiY2YRZZnTkXQyfz8aOfBkQ=
366366
github.com/ipfs/go-ipld-legacy v0.2.2/go.mod h1:hhkj+b3kG9b2BcUNw8IFYAsfeNo8E3U7eYlWeAOPyDU=
367-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a h1:ZtrWQty1MnTu5sJFWpX01KIAEgqmyVphKTmdIbuspm0=
368-
github.com/ipfs/go-log/v2 v2.8.3-0.20251105191458-101e2c1ac85a/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
367+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2 h1:YEH65nXkYTyK4FIIess2VXnPIfioCGABxz4nLgFbyKg=
368+
github.com/ipfs/go-log/v2 v2.8.3-0.20251105220843-b453280b0ce2/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
369369
github.com/ipfs/go-metrics-interface v0.3.0 h1:YwG7/Cy4R94mYDUuwsBfeziJCVm9pBMJ6q/JR9V40TU=
370370
github.com/ipfs/go-metrics-interface v0.3.0/go.mod h1:OxxQjZDGocXVdyTPocns6cOLwHieqej/jos7H4POwoY=
371371
github.com/ipfs/go-peertaskqueue v0.8.2 h1:PaHFRaVFdxQk1Qo3OKiHPYjmmusQy7gKQUaL8JDszAU=

0 commit comments

Comments
 (0)