mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
accesslog: add CSV format
relative to: https://github.com/kataras/iris/issues/1601
This commit is contained in:
34
_examples/logging/request-logger/accesslog-csv/main.go
Normal file
34
_examples/logging/request-logger/accesslog-csv/main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/middleware/accesslog"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
ac := accesslog.File("access_log.csv")
|
||||
ac.SetFormatter(&accesslog.CSV{
|
||||
AutoFlush: true,
|
||||
Header: true,
|
||||
// DateScript: "FROM_UNIX",
|
||||
LatencyRound: time.Second,
|
||||
})
|
||||
|
||||
app.UseRouter(ac.Handler)
|
||||
app.Get("/", index)
|
||||
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func index(ctx iris.Context) {
|
||||
if sleepDur := ctx.URLParam("sleep"); sleepDur != "" {
|
||||
if d, err := time.ParseDuration(sleepDur); err == nil {
|
||||
time.Sleep(d)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.WriteString("Index")
|
||||
}
|
||||
Reference in New Issue
Block a user