main: timestamp formatting in the log

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-09-23 13:37:52 -04:00
parent 178b63b13b
commit a06aa900b7
Signed by: vbatts
GPG Key ID: 10937E57733F1362
1 changed files with 5 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/abbot/go-http-auth" "github.com/abbot/go-http-auth"
"golang.org/x/net/webdav" "golang.org/x/net/webdav"
@ -38,6 +39,8 @@ func main() {
FileSystem: fs, FileSystem: fs,
LockSystem: webdav.NewMemLS(), LockSystem: webdav.NewMemLS(),
Logger: func(r *http.Request, err error) { Logger: func(r *http.Request, err error) {
t := time.Now()
tStamp := fmt.Sprintf("%d.%9.9d", t.Unix(), t.Nanosecond())
switch r.Method { switch r.Method {
case "COPY", "MOVE": case "COPY", "MOVE":
dst := "" dst := ""
@ -45,9 +48,9 @@ func main() {
dst = u.Path dst = u.Path
} }
o := r.Header.Get("Overwrite") o := r.Header.Get("Overwrite")
log.Printf("%-20s%-20s%-10s%-30s%-30so=%-2s%v", r.Header.Get("Date"), r.RemoteAddr, r.Method, r.URL.Path, dst, o, err) log.Printf("%-21s%-25s%-10s%-30s%-30so=%-2s%v", tStamp, r.RemoteAddr, r.Method, r.URL.Path, dst, o, err)
default: default:
log.Printf("%-20s%-20s%-10s%-30s%v", r.Header.Get("Date"), r.RemoteAddr, r.Method, r.URL.Path, err) log.Printf("%-21s%-25s%-10s%-30s%v", tStamp, r.RemoteAddr, r.Method, r.URL.Path, err)
} }
}, },
} }