duanpu1064 2013-01-10 07:26
浏览 28
已采纳

log4go的异常行为

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?

  • 写回答

4条回答 默认 最新

  • dsqve08622 2013-01-12 00:08
    关注

    After checking the issues on log4go website, it seems that the log4go has a flushing problem.

    Becuase it uses a channel to write to files, if the main exits 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败