I found the log4go package loses logs from time to time.
Following is a simple code snippet(I moved the log4go directory so the following import is ok.):
package main
import (
"log4go"
"log"
"fmt"
)
func main() {
fmt.Println("fmt")
log.Println("log")
log4go.Info("log4go")
log4go.Info("log4go")
}
Then I executed it by go run test.go, and the output is as follows:
fmt
2013/01/10 15:24:04 log
The messages by log4go are not written to output.
Why?
After checking the issues on
log4gowebsite, it seems that thelog4gohas a flushing problem.Becuase it uses a
channelto write to files, if themainexits too fast, the log content will not be written.So adding a
time.Sleep(time.Second)to the end of the code snippeet will cause the log content flush.