Improve logging

This commit is contained in:
viktorstrate
2020-02-21 21:00:40 +01:00
parent 935dc5b55e
commit 37aea1fb3a
3 changed files with 17 additions and 2 deletions

View File

@@ -27,7 +27,7 @@ import (
func ProcessImage(tx *sql.Tx, photoPath string, albumId int, content_type string) error {
log.Printf("Processing image: %s\n", photoPath)
// log.Printf("Processing image: %s\n", photoPath)
photoName := path.Base(photoPath)

View File

@@ -42,6 +42,8 @@ func CORSMiddleware(devMode bool) mux.MiddlewareFunc {
if req.Method != http.MethodOptions {
next.ServeHTTP(w, req)
} else {
w.WriteHeader(200)
}
})
}

View File

@@ -37,13 +37,26 @@ func LoggingMiddleware(next http.Handler) http.Handler {
statusColor = color.Colorize("r")
}
method := r.Method
var methodColor string
switch {
case method == http.MethodGet:
methodColor = color.Colorize("b")
case method == http.MethodPost:
methodColor = color.Colorize("g")
case method == http.MethodOptions:
methodColor = color.Colorize("y")
default:
methodColor = color.Colorize("r")
}
user := auth.UserFromContext(r.Context())
userText := "unauthenticated"
if user != nil {
userText = color.Sprintf("@ruser: %s", user.Username)
}
statusText := color.Sprintf("%s%s %d", statusColor, r.Method, status)
statusText := color.Sprintf("%s%s %s%d", methodColor, r.Method, statusColor, status)
requestText := fmt.Sprintf("%s%s", r.Host, r.URL.Path)
durationText := color.Sprintf("@c%s", elapsed)