From 7ed7291c6b28d2468dc3ed4d57135f696fd0ea6f Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Thu, 12 Nov 2020 14:10:50 -0800 Subject: [PATCH] Fix log entry for requests with blank path --- go.mod | 2 +- go.sum | 4 ++-- server.go | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index e4c6dc8..ac0d967 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,6 @@ require ( github.com/h2non/filetype v1.1.0 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/yookoala/gofast v0.4.1-0.20201013050739-975113c54107 - golang.org/x/tools v0.0.0-20201112171726-b38955972a18 // indirect + golang.org/x/tools v0.0.0-20201112185108-eeaa07dd7696 // indirect gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 ) diff --git a/go.sum b/go.sum index 29a6a0a..fd7dd72 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= -golang.org/x/tools v0.0.0-20201112171726-b38955972a18 h1:zCVX0Qx6zEiwi5lM2jprfSFA6i6GWMXmY8o0VxPyCfo= -golang.org/x/tools v0.0.0-20201112171726-b38955972a18/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201112185108-eeaa07dd7696 h1:Bfazo+enXJET5SbHeh95NtxabJF6fJ9r/jpfRJgd3j4= +golang.org/x/tools v0.0.0-20201112185108-eeaa07dd7696/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/server.go b/server.go index 516fcae..7b491f7 100644 --- a/server.go +++ b/server.go @@ -395,13 +395,20 @@ func logEntry(request *url.URL, status int, size int64, elapsed time.Duration) [ hostFormatted += ":1965" } } - timeFormatted := time.Now().Format("02/Jan/2006 03:04:05") + + timeFormatted := time.Now().Format("2006-01-02 15:04:05") + + pathFormatted := request.Path + if pathFormatted == "" { + pathFormatted = "-" + } + sizeFormatted := "-" if size >= 0 { sizeFormatted = strconv.FormatInt(size, 10) } - return []byte(fmt.Sprintf(`%s - - - [%s] "GET %s Gemini" %d %s %.4f`, hostFormatted, timeFormatted, request.Path, status, sizeFormatted, elapsed.Seconds())) + return []byte(fmt.Sprintf(`%s - - - [%s] "GET %s Gemini" %d %s %.4f`, hostFormatted, timeFormatted, pathFormatted, status, sizeFormatted, elapsed.Seconds())) } func handleListener(l net.Listener) {