Iris: LOG: Support log rotate?

Created on 20 Sep 2017  路  7Comments  路  Source: kataras/iris

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.
}
waiting for more information

All 7 comments

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:

https://github.com/kataras/iris/blob/master/_examples/http_request/request-logger/request-logger-file/main.go

@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.

Was this page helpful?
0 / 5 - 0 ratings