mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
accesslog middleware: add total bytes received and sent
relative to: https://github.com/kataras/iris/issues/1601
This commit is contained in:
@@ -25,23 +25,31 @@ func main() {
|
||||
Use a file directly:
|
||||
ac := accesslog.File("./access.log")
|
||||
|
||||
Log after the response was sent:
|
||||
Log after the response was sent (defaults to false):
|
||||
ac.Async = true
|
||||
|
||||
Force-protect writer with locks.
|
||||
On this example this is not required:
|
||||
ac.LockWriter = true"
|
||||
|
||||
// To disable request and response calculations
|
||||
// (enabled by default but slows down the whole operation if Async is false):
|
||||
ac.RequestBody = false
|
||||
ac.ResponseBody = false
|
||||
ac.BytesReceived = false
|
||||
ac.BytesSent = false
|
||||
|
||||
Add second output:
|
||||
ac.AddOutput(app.Logger().Printer)
|
||||
|
||||
Change format (after output was set):
|
||||
ac.SetFormatter(&accesslog.JSON{Indent: " "})
|
||||
|
||||
Change the format and customize the order
|
||||
with the Template format:
|
||||
Modify the output format and customize the order
|
||||
with the Template formatter:
|
||||
ac.SetFormatter(&accesslog.Template{
|
||||
Text: "{{.Now.Format .TimeFormat}}|{{.Latency}}|{{.Method}}|{{.Path}}|{{.RequestValuesLine}}|{{.Code}}|{{.Request}}|{{.Response}}|\n",
|
||||
Text: "{{.Now.Format .TimeFormat}}|{{.Latency}}|{{.Method}}|{{.Path}}|{{.RequestValuesLine}}|{{.Code}}|{{.BytesReceivedLine}}|{{.BytesSentLine}}|{{.Request}}|{{.Response}}|\n",
|
||||
// Default ^
|
||||
})
|
||||
|
||||
Set custom request fields:
|
||||
|
||||
Reference in New Issue
Block a user