sirupsen / logrus

Structured, pluggable logging for Go.
MIT License
24.76k stars 2.27k forks source link

logrus setoutput log to file, but Unable to view logs in real time through linux tail -f #1358

Closed StandNorthStar closed 1 year ago

StandNorthStar commented 2 years ago

I want to verify the logrus output log and view the log in real time through tail -f. But the resulting log file must be reopened to see the latest content.

I don't know why, can you give me some advice

logrus version: logrus v1.8.1 golang version: go1.16.6 --- test code start ---

func main() { logger.SetFormatter(&logrus.TextFormatter{TimestampFormat: "2006-01-02 15:04:05", DisableColors: true}) logger.Level = logrus.TraceLevel logger.ReportCaller = true

file, _ = os.OpenFile("./test.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
logger.SetOutput(io.MultiWriter(file))

for i:=1; i<10;i++ {
    fmt.Println("start :", i)
    logger.Info(fmt.Sprintf("mine: %d", i))
    time.Sleep(time.Second * 5)
}

} --- test code end ---

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.