1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +00:00

accesslog middleware: add total bytes received and sent

relative to: https://github.com/kataras/iris/issues/1601
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-08 13:44:50 +03:00
parent a4996b90c8
commit d6867e1f9e
7 changed files with 223 additions and 53 deletions

View File

@@ -1,6 +1,6 @@
2020-08-22 00:44:20|993.3µs|POST|/read_body||200|{"id":10,"name":"Tim","age":22}|{"message":"OK"}|
2020-08-22 00:44:30|0s|POST|/read_body||400||error(invalid character 'a' looking for beginning of object key string)||
2020-08-22 03:02:41|1ms|GET|/|a=1 b=2|200||<h1>Hello index</h1>|
2020-08-22 03:15:29|968.8µs|GET|/public|file=public|404|||
2020-08-22 03:03:42|0s|GET|/user/kataras|username=kataras|200||Hello, kataras!|
2020-08-22 03:05:40|0s|GET|/user/kataras|username=kataras a_query_parameter=name|200||Hello, kataras!|
2020-09-08 13:34:42|0s|POST|/read_body||200|324 B|217 B|{"name":"John","email":"example@example.com"}|{"data":{"email":"example@example.com","name":"John"},"message":"OK"}|
2020-09-08 13:40:28|0s|POST|/read_body||400||85 B|error(invalid character '\r' in string literal)||
2020-09-08 13:41:05|1.0024ms|GET|/|a=1 b=2|200|767 B|251 B||<h1>Hello index</h1>|
2020-09-08 13:41:26|0s|GET|/public||404|765 B|83 B|||
2020-09-08 13:41:36|0s|GET|/user/kataras|username=kataras|200|771 B|91 B||Hello, kataras!|
2020-09-08 13:41:47|0s|GET|/user/kataras|username=kataras a_query_parameter=name|200|774 B|91 B||Hello, kataras!|

View File

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