aboutsummaryrefslogtreecommitdiff
path: root/src/log
diff options
context:
space:
mode:
authorColin Arnott <colin@urandom.co.uk>2020-10-22 22:16:01 +0000
committerIan Lance Taylor <iant@golang.org>2020-10-23 22:08:37 +0000
commit9db7db54b0e84d6b3ace94cb1f2a42e065575f17 (patch)
treea444d325ff20f4a5effb24b1f702e6afbd362c20 /src/log
parenta972e8ccb9824d97f029bde5409527fb27e85989 (diff)
downloadgo-9db7db54b0e84d6b3ace94cb1f2a42e065575f17.tar.gz
go-9db7db54b0e84d6b3ace94cb1f2a42e065575f17.zip
log: expose std via new Default function
To allow passing around the package level *Logger, it is now exposed to callers of the Default function. We considered exposing std, however at this time there is no need to allow callers to replace std only pass and call methods directly. Fixes #39057 Change-Id: I710b16a3aa5e4e878870561dbf59560f98d8d09a Reviewed-on: https://go-review.googlesource.com/c/go/+/264460 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Diffstat (limited to 'src/log')
-rw-r--r--src/log/log.go3
-rw-r--r--src/log/log_test.go6
2 files changed, 9 insertions, 0 deletions
diff --git a/src/log/log.go b/src/log/log.go
index 216cfe0322..8c0f83f0d1 100644
--- a/src/log/log.go
+++ b/src/log/log.go
@@ -75,6 +75,9 @@ func (l *Logger) SetOutput(w io.Writer) {
var std = New(os.Stderr, "", LstdFlags)
+// Default returns the *Logger used by the package-level output functions.
+func Default() *Logger { return std }
+
// Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.
func itoa(buf *[]byte, i int, wid int) {
// Assemble decimal in reverse order.
diff --git a/src/log/log_test.go b/src/log/log_test.go
index cdccbc554d..5be8e82258 100644
--- a/src/log/log_test.go
+++ b/src/log/log_test.go
@@ -74,6 +74,12 @@ func testPrint(t *testing.T, flag int, prefix string, pattern string, useFormat
SetOutput(os.Stderr)
}
+func TestDefault(t *testing.T) {
+ if got := Default(); got != std {
+ t.Errorf("Default [%p] should be std [%p]", got, std)
+ }
+}
+
func TestAll(t *testing.T) {
for _, testcase := range tests {
testPrint(t, testcase.flag, testcase.prefix, testcase.pattern, false)