Skip to content

Commit 33c2d88

Browse files
committed
Revert "log: define G() as a function instead of a variable"
This reverts commit 778ac30. (slightly modified, due to changes that were merged after that). The reverted commit had two elements; - Make `G` an actual function to improve the documentation - Prevent `G` from being overwritten externally From the commit that's reverted: > The `G` variable is exported, and not expected to be overwritten > externally. Defining it as a function also documents it as a function > on https://pkg.go.dev, instead of a variable; https://pkg.go.dev/github.com/containerd/[email protected]/log#pkg-variables While it's unclear if the ability to replace the implementation was _intentional_, it's this part that some external consumers were (ab)using. We should look into that part in a follow-up, and design for this, for example by providing a utility to replace the logger, and properly document that. In the meantime, let's revert the change. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 19d6c37) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 0a7f297 commit 33c2d88

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

log/context.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ import (
4444
"github.com/sirupsen/logrus"
4545
)
4646

47+
// G is a shorthand for [GetLogger].
48+
//
49+
// We may want to define this locally to a package to get package tagged log
50+
// messages.
51+
var G = GetLogger
52+
4753
// L is an alias for the standard logger.
4854
var L = &Entry{
4955
Logger: logrus.StandardLogger(),
@@ -169,11 +175,6 @@ func WithLogger(ctx context.Context, logger *Entry) context.Context {
169175
// GetLogger retrieves the current logger from the context. If no logger is
170176
// available, the default logger is returned.
171177
func GetLogger(ctx context.Context) *Entry {
172-
return G(ctx)
173-
}
174-
175-
// G is a shorthand for [GetLogger].
176-
func G(ctx context.Context) *Entry {
177178
if logger := ctx.Value(loggerKey{}); logger != nil {
178179
return logger.(*Entry)
179180
}

0 commit comments

Comments
 (0)