文件名:appLogger.go
package main
import (
"log"
"os"
"time"
)
var (
logpath = "trace/trace.log"
)
var cLog *appLogger
type appLogger struct {
t *log.Logger
}
func appNewLogger() (*appLogger, error) {
now := time.Now()
dt := now.Format(time.RFC3339)
fp, err := os.Create(logpath + dt)
if err != nil {
return nil, err
}
cLog.t = log.New(fp, "TRACE:", log.Ldate|log.Ltime|log.Lshortfile),
return cLog, nil
}
func (trc *appLogger) trace(f string) {
trc.t.Println(f)
}
我从另一个文件main.go调用上述trace()方法
cLog.trace(“记录已初始化”)
即使从main.go调用了记录器,trace.log文件也始终使用appLogger.go记录log.Lshortfile。这是什么问题?