Go_expvar_log包
Go_expvar_log包
package main
import (
"bytes"
"expvar"
"fmt"
"log"
)
func main() {
var (
buf bytes.Buffer
logger = log.New(&buf, "INFO: ", log.Llongfile)
infof = func(info string) {
logger.Output(2, info)
fmt.Println(&buf)
buf = bytes.Buffer{} // 这里需要gc
}
)
float := expvar.NewFloat("")
float.Set(float64(3.555))
fmt.Println(float.String())
infof(float.String())
infof(float.String())
infof(float.String())
infof(float.String())
}
输出
3.555
INFO: E:/code_me/go-utils/tests_cmd/sim/main.go:26: 3.555
INFO: E:/code_me/go-utils/tests_cmd/sim/main.go:27: 3.555
INFO: E:/code_me/go-utils/tests_cmd/sim/main.go:28: 3.555
INFO: E:/code_me/go-utils/tests_cmd/sim/main.go:29: 3.555