I use log from example file-logger , but it doesn't say how to rotate the log.
Then I use before hook to check log file name and set log output every query, is that right way?
// before all routers need to set default lang
func before(ctx iris.Context) {
lang := ctx.Params().Get("lang")
app := iris.New()
f := newLogFile()
defer f.Close()
app.Logger().SetOutput(newLogFile())
ctx.Next() // execute the next handler, in this case the main one.
}
Hello @mailbaoer, First; do you try to change the application's logger inside a handler? This is not right why you do something like this? Secondly, I don't understand your question, could you please re-form with an example output? what do you expect to see and what you see instead?
@kataras sorry for late! I have a long holidays, so did not see it! Waht I want to do is cut log into pieces, like nginx one day one piece or one hour one piece, how can I do this?
@mailbaoer there is an example over here that shows you how to make daily logs, you can adapt that example to make different intervals of time:
@speedwheel thank you very much! I will try it later!:thumbsup:
@mailbaoer You're welcome!
I feel log rotate is one import feature that we should support! @speedwheel ,as the example code, we should stop our application every day.
Hello, check the https://github.com/kataras/golog/blob/master/_examples/rotation/main.go example one.