Skip to content

Commit 730425a

Browse files
committed
improve log
1 parent 15abe87 commit 730425a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

client_chain_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
)
99

1010
func Test_GetChain(t *testing.T) {
11-
cli := NewClientWithLogger(testnetEndpoint, SimpleStdoutLogger{})
11+
cli := NewClientWithLogger(testnetEndpoint, SimpleLogger)
1212
_, err := cli.GetChain(context.Background(), GetChainOption{Simple: true})
1313
assert.NoError(t, err)
1414
}
1515

1616
func Test_GetLatestBlockHeight(t *testing.T) {
17-
cli := NewClientWithLogger(testnetEndpoint, SimpleStdoutLogger{})
17+
cli := NewClientWithLogger(testnetEndpoint, SimpleLogger)
1818
h, err := cli.GetLatestBlockHeight(context.Background())
1919
assert.NoError(t, err)
2020
fmt.Printf("%d\n", h)

log.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@ package fuel
22

33
import (
44
"fmt"
5-
"time"
5+
"log"
6+
"os"
67
)
78

89
type Logger interface {
910
Infof(template string, args ...any)
1011
}
1112

12-
type SimpleStdoutLogger struct{}
13+
type simpleLogger log.Logger
1314

14-
func (l SimpleStdoutLogger) Infof(template string, args ...any) {
15-
fmt.Printf(time.Now().String()+" "+template+"\n", args...)
15+
func (l *simpleLogger) Infof(template string, args ...any) {
16+
_ = (*log.Logger)(l).Output(2, fmt.Sprintf(template+"\n", args...))
17+
}
18+
19+
var SimpleLogger *simpleLogger
20+
21+
func init() {
22+
SimpleLogger = (*simpleLogger)(log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile))
1623
}

0 commit comments

Comments
 (0)