记录日志很方便~
package main
import (
"fmt"
"log"
"os"
)
func main() {
fmt.Println("start")
log.Println("start test log")
fp,err := os.Create("test.log")
if err != nil {
log.Fatalln("create file faild")
os.Exit(-1)
}
defer fp.Close()
aLoger := log.New(fp,"",log.LstdFlags|log.Llongfile)
log.Println("step1:")
aLoger.Println("1 step log result")
log.Println("step2:")
//aLoger.SetFlags(log.LstdFlags)
aLoger.Println("2 step log result")
log.Println("step3:")
aLoger.Fatalln("3 step log result")
}