// Use the following code if you need to write the logs to file and console at the same time. // gin.DefaultWriter = io.MultiWriter(f, os.Stdout) 但用os.Create 会造成每次重启 gin 服务,都会清空日志文件,所以优化一下: logFile, _ := os.OpenFile("access.log", os.O_APPEND|os.O_CR...
package main import ( "fmt" "/hpcloud/tail" "time" ) func main() { fileName := "./my.log" config := tail.Config{ ReOpen: true, // 重新打开 Follow: true, // 是否跟随 Location: &tail.SeekInfo{Offset: 0, Whence: 2}, // 从文件的哪个地方开始读 MustExist: false, // 文件不存...
1funcmain(){2fileName:="/Users/zt/Desktop/Info_First.log"//路径+文件名3logFile,err:=os.Create(fileName)4defer logFile.Close()5iferr!=nil{6log.Fatalln("open file error")7}8debugLog:=log.New(logFile,"[Info]",log.Llongfile)9debugLog.Println("A Info message here")10debugLog.SetPr...
AI代码解释 logger,_:=zap.NewProduction()defer logger.Sync()logger.Info("failed to fetch URL",// 结构化上下文作为强类型的字段值。zap.String("url",url),zap.Int("attempt",3),zap.Duration("backoff",time.Second),)
())}func getLogWriter() zapcore.WriteSyncer {//如果想要追加写入可以查看我的博客文件操作那一章file, _ := os.Create("./test.log")return zapcore.AddSync(file)}func simpleHttpGet(url string) {sugarLogger.Debugf("Trying to hit GET request for %s", url)resp, err := http.Get(url)if ...
file,_:=os.Create(LogPath)core:=zapcore.NewTee(zapcore.NewCore(zapcore.NewJSONEncoder(cfg),zapcore.AddSync(file),zapcore.InfoLevel),zapcore.NewCore(zapcore.NewConsoleEncoder(cfg)),zapcore.Lock(os.Stdout),zapcore.DebugLevel),)logger:=zap.New(core)defer logger.Sync() ...
This repository is reconstructed from alecthomas's log4go, which is a logging package similar to log4j for the Go programming language. Two new features are supported: one is Json config style, and the other is different output according to category. Features Log to console Log to file, suppo...
{"file":"/Users/xiaohe/go/src/github.com/he2121/log_test/main.go:12","func":"main.main","level":"info","msg":"Info 日志","time":"2021-11-09T17:37:27+08:00"}{"file":"/Users/xiaohe/go/src/github.com/he2121/log_test/main.go:13","func":"main.main","level":"warning"...
写日志即可 export GLC_ENABLE=true # 此配置默认false,要发送日志中心必须配置为true export GLC_ENABLE_CONSOLE_LOG=true # 默认true,控制台不打印时配置为false export GLC_API_URL='http://127.0.0.1:8080/' # 未配置时将取消发送 export GLC_API_KEY='X-GLC-AUTH:glogcenter' # 这是默认值,按需修改...
FunctionfunctionstringThe function name to call loggermain.main If you want to customize the format of the log output ? config format: consoleConfig := &go_logger.ConsoleConfig{ Format: "%millisecond_format% [%level_string%] %body%", } fileConfig := &go_logger.FileConfig{ Format: "%mill...