Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log/slog: change XXXCtx function names to XXXContext #61200

Closed
jba opened this issue Jul 6, 2023 · 7 comments
Closed

log/slog: change XXXCtx function names to XXXContext #61200

jba opened this issue Jul 6, 2023 · 7 comments

Comments

@jba
Copy link
Contributor

jba commented Jul 6, 2023

For consistency with the rest of the standard library, the names of InfoCtx and related functions should be changed to InfoContext, etc.

@jba jba added the Proposal label Jul 6, 2023
@jba jba self-assigned this Jul 6, 2023
@gopherbot gopherbot added this to the Proposal milestone Jul 6, 2023
@rsc rsc added this to Proposals Jul 6, 2023
@rsc rsc moved this to Incoming in Proposals Jul 6, 2023
@rsc
Copy link
Contributor

rsc commented Jul 6, 2023

Not sure how we missed this.

% grep 'Ctx(' *
go1.21.txt:pkg log/slog, func DebugCtx(context.Context, string, ...interface{}) #56345
go1.21.txt:pkg log/slog, func ErrorCtx(context.Context, string, ...interface{}) #56345
go1.21.txt:pkg log/slog, func InfoCtx(context.Context, string, ...interface{}) #56345
go1.21.txt:pkg log/slog, func WarnCtx(context.Context, string, ...interface{}) #56345
go1.21.txt:pkg log/slog, method (*Logger) DebugCtx(context.Context, string, ...interface{}) #56345
go1.21.txt:pkg log/slog, method (*Logger) ErrorCtx(context.Context, string, ...interface{}) #56345
go1.21.txt:pkg log/slog, method (*Logger) InfoCtx(context.Context, string, ...interface{}) #56345
go1.21.txt:pkg log/slog, method (*Logger) WarnCtx(context.Context, string, ...interface{}) #56345
% grep 'Context(' *
go1.1.txt:pkg text/template, method (Template) ErrorContext(parse.Node) (string, string)
go1.1.txt:pkg text/template/parse, method (*Tree) ErrorContext(Node) (string, string)
go1.13.txt:pkg net/http, func NewRequestWithContext(context.Context, string, string, io.Reader) (*Request, error)
go1.15.txt:pkg crypto/tls, method (*Dialer) DialContext(context.Context, string, string) (net.Conn, error)
go1.16.txt:pkg os/signal, func NotifyContext(context.Context, ...os.Signal) (context.Context, context.CancelFunc)
go1.17.txt:pkg crypto/tls, method (*CertificateRequestInfo) Context() context.Context
go1.17.txt:pkg crypto/tls, method (*ClientHelloInfo) Context() context.Context
go1.17.txt:pkg crypto/tls, method (*Conn) HandshakeContext(context.Context) error
go1.18.txt:pkg go/types, func NewContext() *Context
go1.7.txt:pkg net, method (*Dialer) DialContext(context.Context, string, string) (Conn, error)
go1.7.txt:pkg net/http, method (*Request) Context() context.Context
go1.7.txt:pkg net/http, method (*Request) WithContext(context.Context) *Request
go1.7.txt:pkg os/exec, func CommandContext(context.Context, string, ...string) *Cmd
go1.8.txt:pkg database/sql/driver, type ConnPrepareContext interface, PrepareContext(context.Context, string) (Stmt, error)
go1.8.txt:pkg database/sql/driver, type ExecerContext interface, ExecContext(context.Context, string, []NamedValue) (Result, error)
go1.8.txt:pkg database/sql/driver, type QueryerContext interface, QueryContext(context.Context, string, []NamedValue) (Rows, error)
go1.8.txt:pkg database/sql/driver, type StmtExecContext interface, ExecContext(context.Context, []NamedValue) (Result, error)
go1.8.txt:pkg database/sql/driver, type StmtQueryContext interface, QueryContext(context.Context, []NamedValue) (Rows, error)
go1.8.txt:pkg database/sql, method (*DB) ExecContext(context.Context, string, ...interface{}) (Result, error)
go1.8.txt:pkg database/sql, method (*DB) PingContext(context.Context) error
go1.8.txt:pkg database/sql, method (*DB) PrepareContext(context.Context, string) (*Stmt, error)
go1.8.txt:pkg database/sql, method (*DB) QueryContext(context.Context, string, ...interface{}) (*Rows, error)
go1.8.txt:pkg database/sql, method (*DB) QueryRowContext(context.Context, string, ...interface{}) *Row
go1.8.txt:pkg database/sql, method (*Stmt) ExecContext(context.Context, ...interface{}) (Result, error)
go1.8.txt:pkg database/sql, method (*Stmt) QueryContext(context.Context, ...interface{}) (*Rows, error)
go1.8.txt:pkg database/sql, method (*Stmt) QueryRowContext(context.Context, ...interface{}) *Row
go1.8.txt:pkg database/sql, method (*Tx) ExecContext(context.Context, string, ...interface{}) (Result, error)
go1.8.txt:pkg database/sql, method (*Tx) PrepareContext(context.Context, string) (*Stmt, error)
go1.8.txt:pkg database/sql, method (*Tx) QueryContext(context.Context, string, ...interface{}) (*Rows, error)
go1.8.txt:pkg database/sql, method (*Tx) QueryRowContext(context.Context, string, ...interface{}) *Row
go1.8.txt:pkg database/sql, method (*Tx) StmtContext(context.Context, *Stmt) *Stmt
go1.9.txt:pkg database/sql, method (*Conn) ExecContext(context.Context, string, ...interface{}) (Result, error)
go1.9.txt:pkg database/sql, method (*Conn) PingContext(context.Context) error
go1.9.txt:pkg database/sql, method (*Conn) PrepareContext(context.Context, string) (*Stmt, error)
go1.9.txt:pkg database/sql, method (*Conn) QueryContext(context.Context, string, ...interface{}) (*Rows, error)
go1.9.txt:pkg database/sql, method (*Conn) QueryRowContext(context.Context, string, ...interface{}) *Row
go1.txt:pkg regexp/syntax, func EmptyOpContext(int32, int32) EmptyOp
go1.txt:pkg syscall (windows-386), func CertCreateCertificateContext(uint32, *uint8, uint32) (*CertContext, error)
go1.txt:pkg syscall (windows-386), func CertFreeCertificateContext(*CertContext) error
go1.txt:pkg syscall (windows-386), func CryptAcquireContext(*Handle, *uint16, *uint16, uint32, uint32) error
go1.txt:pkg syscall (windows-386), func CryptReleaseContext(Handle, uint32) error
go1.txt:pkg syscall (windows-amd64), func CertCreateCertificateContext(uint32, *uint8, uint32) (*CertContext, error)
go1.txt:pkg syscall (windows-amd64), func CertFreeCertificateContext(*CertContext) error
go1.txt:pkg syscall (windows-amd64), func CryptAcquireContext(*Handle, *uint16, *uint16, uint32, uint32) error
go1.txt:pkg syscall (windows-amd64), func CryptReleaseContext(Handle, uint32) error
% 

Seems reasonable, and worth doing before the next release candidate. OK to submit before this proposal is accepted.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/508195 mentions this issue: log/slog: change XXXCtx functions to XXXContext

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/508215 mentions this issue: slog: rename XXXCtx to XXXContext

@AndrewHarrisSPU
Copy link

AndrewHarrisSPU commented Jul 6, 2023

#56345 (comment) mentioned readability, just want to double-check that this is preferred:

log.InfoContext(ctx, "msg", "key", val)

over:

log.Log(ctx, slog.LevelInfo, "msg", "key", val)

@jba
Copy link
Contributor Author

jba commented Jul 6, 2023

Either one is fine.
I think InfoContext is easier to read: it's clearer that it's at info level.
You need Log to use a level other than the four named ones.
But if a team wants to use Log for everything, that seems fine to me.

gopherbot pushed a commit to golang/exp that referenced this issue Jul 11, 2023
See golang/go#61200 for, um, context.

Add XXXContext methods, but keep the XXXCtx methods around
(deprecated) to avoid breaking people.

Change-Id: I6835658615fb4979b03f5ae0516ac8f79b0f241d
Reviewed-on: https://go-review.googlesource.com/c/exp/+/508215
Run-TryBot: Jonathan Amsterdam <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/509099 mentions this issue: all: update vendored dependencies

@rsc
Copy link
Contributor

rsc commented Jul 12, 2023

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

@rsc rsc moved this from Incoming to Accepted in Proposals Jul 12, 2023
@rsc rsc changed the title proposal: log/slog: change XXXCtx function names to XXXContext log/slog: change XXXCtx function names to XXXContext Jul 12, 2023
@rsc rsc modified the milestones: Proposal, Backlog Jul 12, 2023
gopherbot pushed a commit that referenced this issue Jul 12, 2023
Generated by:

	go install golang.org/x/tools/cmd/bundle@latest
	go install golang.org/x/build/cmd/updatestd@latest
	updatestd -goroot=$GOROOT -branch=master

For #36905.
For #55079.

Fixes #61174 (vet checkers understanding Go language version).
Fixes #61200 (slog InfoCtx -> InfoContext etc).

Change-Id: I4f2c86960ce72d6df06e23da1b1297ab3ff2eecf
Reviewed-on: https://go-review.googlesource.com/c/go/+/509099
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
@dmitshur dmitshur modified the milestones: Backlog, Go1.21 Jul 15, 2023
bradfitz pushed a commit to tailscale/go that referenced this issue Jul 15, 2023
Fixes golang#61200.

Change-Id: I3071dbf673bcd2d24e62644b40d481c953703978
Reviewed-on: https://go-review.googlesource.com/c/go/+/508195
Run-TryBot: Jonathan Amsterdam <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
bradfitz pushed a commit to tailscale/go that referenced this issue Jul 15, 2023
Generated by:

	go install golang.org/x/tools/cmd/bundle@latest
	go install golang.org/x/build/cmd/updatestd@latest
	updatestd -goroot=$GOROOT -branch=master

For golang#36905.
For golang#55079.

Fixes golang#61174 (vet checkers understanding Go language version).
Fixes golang#61200 (slog InfoCtx -> InfoContext etc).

Change-Id: I4f2c86960ce72d6df06e23da1b1297ab3ff2eecf
Reviewed-on: https://go-review.googlesource.com/c/go/+/509099
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
eric pushed a commit to fancybits/go that referenced this issue Sep 7, 2023
Fixes golang#61200.

Change-Id: I3071dbf673bcd2d24e62644b40d481c953703978
Reviewed-on: https://go-review.googlesource.com/c/go/+/508195
Run-TryBot: Jonathan Amsterdam <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
eric pushed a commit to fancybits/go that referenced this issue Sep 7, 2023
Fixes golang#61200.

Change-Id: I3071dbf673bcd2d24e62644b40d481c953703978
Reviewed-on: https://go-review.googlesource.com/c/go/+/508195
Run-TryBot: Jonathan Amsterdam <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
awly pushed a commit to tailscale/go that referenced this issue Feb 7, 2024
Generated by:

	go install golang.org/x/tools/cmd/bundle@latest
	go install golang.org/x/build/cmd/updatestd@latest
	updatestd -goroot=$GOROOT -branch=master

For golang#36905.
For golang#55079.

Fixes golang#61174 (vet checkers understanding Go language version).
Fixes golang#61200 (slog InfoCtx -> InfoContext etc).

Change-Id: I4f2c86960ce72d6df06e23da1b1297ab3ff2eecf
Reviewed-on: https://go-review.googlesource.com/c/go/+/509099
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
@golang golang locked and limited conversation to collaborators Jul 14, 2024
@rsc rsc removed this from Proposals Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants