mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 21:59:12 +00:00
Improve logging
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ func CORSMiddleware(devMode bool) mux.MiddlewareFunc {
|
||||
|
||||
if req.Method != http.MethodOptions {
|
||||
next.ServeHTTP(w, req)
|
||||
} else {
|
||||
w.WriteHeader(200)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user