安装zerolog库的命令行如下:
go get -u github.com/rs/zerolog/log
运行结果如下:
go get: module github.com/rs/zerolog/log: Get "https://proxy.golang.org/github.com/rs/zerolog/log/@v/list": dial tcp 142.251.43.17:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
输入命令行如下:
$env:GOPROXY="https://proxy.golang.com.cn,direct"
再次安装zerolog库的运行结果如下:
go get github.com/rs/zerolog/log: github.com/rs/zerolog@v1.26.1: verifying module: github.com/rs/zerolog@v1.26.1: checking tree#9452087 against tree#9588719: Get "https://proxy.golang.com.cn/sumdb/sum.golang.org/tile/8/0/x036/922": read tcp 192.168.0.197:59917->124.14.21.12:443: wsarecv: An existing connection was forcibly closed by the remote host.
输入代码如下:
package main
import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Print("Hey! I'm a log message!")
}
运行结果如下:
main.go:4:2: no required module provides package github.com/rs/zerolog: go.mod file not found in current directory or any parent directory; see 'go help modules'
main.go:5:2: no required module provides package github.com/rs/zerolog/log: go.mod file not found in current directory or any parent directory; see 'go help modules'
来源于了解如何在 Go 中记录 - Learn | Microsoft Docs
了解如何在Go中记录。