import ( "fmt" "log" "os" ) func init() { logFile, err := os.OpenFile("./xx.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) if err != nil { fmt.Println("open log file failed, err:", err) return } log.SetOutput(logFile) log.SetPrefix("[测试调试]") log.SetFlags(log.Lshortfile |log.Lmicroseconds | log.Ldate) } func main() { fmt.Println("________") log.Println("对应需要打印数据的位置") fmt.Println("_________+") }