1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 21:15:56 +00:00

accesslog: add a blank configuration field as requested at #1627

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-13 17:01:57 +03:00
parent 99fd50bf9d
commit fb00ecd2b7
2 changed files with 59 additions and 5 deletions

View File

@@ -169,6 +169,40 @@ func TestAccessLogBroker(t *testing.T) {
ac.Close()
}
func TestAccessLogBlank(t *testing.T) {
w := new(bytes.Buffer)
ac := New(w)
clockTime, _ := time.Parse(defaultTimeFormat, "1993-01-01 05:00:00")
ac.Clock = TClock(clockTime)
ac.Blank = []byte("<no value>")
ac.Print(
nil,
time.Second,
defaultTimeFormat,
200,
"GET",
"/",
"127.0.0.1",
"",
"",
0,
0,
nil,
nil,
nil,
)
ac.Close()
// the request and bodies length are enabled by-default, zero bytes length
// are written with 0 B and this cannot changed, so the request field
// should be written as "<no value>".
expected := "1993-01-01 05:00:00|1s|200|GET|/|127.0.0.1|0 B|0 B|<no value>|\n"
if got := w.String(); expected != got {
t.Fatalf("expected:\n'%s'\n\nbut got:\n'%s'", expected, got)
}
}
type noOpFormatter struct{}
func (*noOpFormatter) SetOutput(io.Writer) {}