]> Cypherpunks.ru repositories - gostls13.git/commitdiff
log: expose std via new Default function
authorColin Arnott <colin@urandom.co.uk>
Thu, 22 Oct 2020 22:16:01 +0000 (22:16 +0000)
committerIan Lance Taylor <iant@golang.org>
Fri, 23 Oct 2020 22:08:37 +0000 (22:08 +0000)
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>

src/log/log.go
src/log/log_test.go

index 216cfe03222a9704ad16f3dfc81a0e5cd93fc90a..8c0f83f0d184e2f1d8655dfee028f4c8c66a8e0f 100644 (file)
@@ -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.
index cdccbc554d8a002913110e8ebfc85fb7f76cb0d0..5be8e822586f5bc83d88cb7b50a2d4809ecaef78 100644 (file)
@@ -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)