1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:56:12 -07:00

log: use strings.Builder

Change-Id: I02c4664f1ba72623a5470e92bbebabb2f4862428
Reviewed-on: https://go-review.googlesource.com/c/go/+/428264
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
cuiweixie 2022-09-04 18:06:50 +08:00 committed by Gopher Robot
parent 7c47c9773c
commit e3885c4ee5

View File

@ -53,7 +53,7 @@ var tests = []tester{
// Test using Println("hello", 23, "world") or using Printf("hello %d world", 23) // Test using Println("hello", 23, "world") or using Printf("hello %d world", 23)
func testPrint(t *testing.T, flag int, prefix string, pattern string, useFormat bool) { func testPrint(t *testing.T, flag int, prefix string, pattern string, useFormat bool) {
buf := new(bytes.Buffer) buf := new(strings.Builder)
SetOutput(buf) SetOutput(buf)
SetFlags(flag) SetFlags(flag)
SetPrefix(prefix) SetPrefix(prefix)
@ -90,7 +90,7 @@ func TestAll(t *testing.T) {
func TestOutput(t *testing.T) { func TestOutput(t *testing.T) {
const testString = "test" const testString = "test"
var b bytes.Buffer var b strings.Builder
l := New(&b, "", 0) l := New(&b, "", 0)
l.Println(testString) l.Println(testString)
if expect := testString + "\n"; b.String() != expect { if expect := testString + "\n"; b.String() != expect {
@ -143,7 +143,7 @@ func TestFlagAndPrefixSetting(t *testing.T) {
} }
func TestUTCFlag(t *testing.T) { func TestUTCFlag(t *testing.T) {
var b bytes.Buffer var b strings.Builder
l := New(&b, "Test:", LstdFlags) l := New(&b, "Test:", LstdFlags)
l.SetFlags(Ldate | Ltime | LUTC) l.SetFlags(Ldate | Ltime | LUTC)
// Verify a log message looks right in the right time zone. Quantize to the second only. // Verify a log message looks right in the right time zone. Quantize to the second only.
@ -167,7 +167,7 @@ func TestUTCFlag(t *testing.T) {
} }
func TestEmptyPrintCreatesLine(t *testing.T) { func TestEmptyPrintCreatesLine(t *testing.T) {
var b bytes.Buffer var b strings.Builder
l := New(&b, "Header:", LstdFlags) l := New(&b, "Header:", LstdFlags)
l.Print() l.Print()
l.Println("non-empty") l.Println("non-empty")