kataras / kataras/iris

AccessLog can not flush into file until I stop the app

Open
#2,120 2 comments 0 reactions 0 assignees View on GitHub
🤔 type:question
Dominant language
Go
Stars
25.6k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

The configure the accesslog as follow:
`func MakeAccessLog(path string) *accesslog.AccessLog {
pathToAccessLog := "./access_log.%Y%m%d"
w, err := rotatelogs.New(
pathToAccessLog,
rotatelogs.WithMaxAge(24*time.Hour),
rotatelogs.WithRotationTime(time.Hour))
if err != nil {
panic(err)
}
ac := accesslog.New(bufio.NewWriter(w))
ac.AddOutput(os.Stdout)
ac.Delim = '-'
ac.TimeFormat = "2006-01-02 15:04:05"
ac.Async = true
ac.IP = true
ac.BytesReceivedBody = true
ac.BytesSentBody = true
ac.BytesSent = false
ac.BytesReceived = false
ac.BodyMinify = true
ac.RequestBody = false
ac.ResponseBody = false
ac.KeepMultiLineError = true
ac.PanicLog = accesslog.LogHandler
ac.SetFormatter(&accesslog.JSON{
HumanTime: true,
})
return ac
}
//use it in my app
ac := common.MakeAccessLog("./access.log")
defer ac.Close()
app.UseRouter(ac.Handler)`
when I access the app, the standout ouput the accesslog normally,but the log file didn't create at the app start,but when I stopped the app ,the file and the log reocord appeared.

Contributor guide

Open the contributing guide

Research direction

Reproduce the delayed file output using the shown accesslog.New, bufio.NewWriter, and rotatelogs.New setup, then trace how app.UseRouter and ac.Close affect writes. Compare the stdout and file outputs while the app is running; done means access records appear in the rotated file before shutdown.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.