Go Log模块生成日志文件
使用log模块示例代码:
package main import ( "fmt" "time" "log" "os" ) func main() { go func() { defer func() { i := recover() if i != nil { file, _ := os.Create("error.log") defer file.Close() logger := log.New(file, "[Error] ", log.Ldate|log.Ltime) // [Error] 2018/07/28 17:43:23 runtime error: invalid memory address or nil pointer dereference logger.Println(i) } }() var p *int //p = new(int) *p = 1000 fmt.Println("hello") }() time.Sleep(time.Second) fmt.Println("hello main") }