Skip to content

Commit 0181290

Browse files
committed
ulog: depend on log.Default() so prefixes are propagated through ulog.Log
Signed-off-by: Chris Koch <[email protected]>
1 parent c353755 commit 0181290

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/u-root/uio
22

3-
go 1.15
3+
go 1.16
44

55
require (
66
github.com/josharian/native v1.0.1-0.20221213033349-c1e37c09b531

ulog/log.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
// testing.TB.Logf. To use the test logger import "ulog/ulogtest".
1010
package ulog
1111

12-
import (
13-
"log"
14-
"os"
15-
)
12+
import "log"
1613

1714
// Logger is a log receptacle.
1815
//
@@ -22,8 +19,8 @@ type Logger interface {
2219
Print(v ...interface{})
2320
}
2421

25-
// Log is a Logger that prints to stderr, like the default log package.
26-
var Log Logger = log.New(os.Stderr, "", log.LstdFlags)
22+
// Log is a Logger that prints to the log package's default logger.
23+
var Log Logger = log.Default()
2724

2825
type emptyLogger struct{}
2926

ulog/log_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ulog
2+
3+
import (
4+
"log"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestDefault(t *testing.T) {
10+
var b strings.Builder
11+
log.SetPrefix("[foobar] ")
12+
log.SetOutput(&b)
13+
log.SetFlags(0)
14+
15+
Log.Printf("Some output")
16+
17+
want := "[foobar] Some output\n"
18+
if got := b.String(); got != want {
19+
t.Errorf("log is %q, want %q", got, want)
20+
}
21+
}

0 commit comments

Comments
 (0)