Merge pull request #9644 from owncloud/collaboration_infolog

feat: use info level for access log to the collaboration service
This commit is contained in:
Michael Barz
2024-07-18 16:02:30 +02:00
committed by GitHub
3 changed files with 43 additions and 9 deletions
@@ -65,6 +65,7 @@ func (h *HttpAdapter) GetLock(w http.ResponseWriter, r *http.Request) {
return return
} }
w.Header().Set(HeaderWopiLock, lockID) w.Header().Set(HeaderWopiLock, lockID)
w.WriteHeader(http.StatusOK)
} }
// Lock adapts the "Lock" and "UnlockAndRelock" operations for WOPI. // Lock adapts the "Lock" and "UnlockAndRelock" operations for WOPI.
@@ -91,8 +92,7 @@ func (h *HttpAdapter) Lock(w http.ResponseWriter, r *http.Request) {
} }
return return
} }
// If no error, a HTTP 200 should be sent automatically. w.WriteHeader(http.StatusOK)
// X-WOPI-Lock header isn't needed on HTTP 200
} }
// RefreshLock adapts the "RefreshLock" operation for WOPI // RefreshLock adapts the "RefreshLock" operation for WOPI
@@ -119,8 +119,7 @@ func (h *HttpAdapter) RefreshLock(w http.ResponseWriter, r *http.Request) {
} }
return return
} }
// If no error, a HTTP 200 should be sent automatically. w.WriteHeader(http.StatusOK)
// X-WOPI-Lock header isn't needed on HTTP 200
} }
// UnLock adapts the "Unlock" operation for WOPI // UnLock adapts the "Unlock" operation for WOPI
@@ -145,8 +144,7 @@ func (h *HttpAdapter) UnLock(w http.ResponseWriter, r *http.Request) {
} }
return return
} }
// If no error, a HTTP 200 should be sent automatically. w.WriteHeader(http.StatusOK)
// X-WOPI-Lock header isn't needed on HTTP 200
} }
// CheckFileInfo will retrieve the information of the file in json format // CheckFileInfo will retrieve the information of the file in json format
@@ -229,6 +227,5 @@ func (h *HttpAdapter) PutFile(w http.ResponseWriter, r *http.Request) {
} }
return return
} }
// If no error, a HTTP 200 should be sent automatically. w.WriteHeader(http.StatusOK)
// X-WOPI-Lock header isn't needed on HTTP 200
} }
@@ -0,0 +1,37 @@
package middleware
import (
"net/http"
"time"
"github.com/go-chi/chi/v5/middleware"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"go.opentelemetry.io/otel/trace"
)
// AccessLog is a middleware to log http requests at info level logging.
func AccessLog(logger log.Logger) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
requestID := middleware.GetReqID(r.Context())
// add Request Id to all responses
w.Header().Set(middleware.RequestIDHeader, requestID)
wrap := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
next.ServeHTTP(wrap, r)
spanContext := trace.SpanContextFromContext(r.Context())
logger.Info().
Str("proto", r.Proto).
Str(log.RequestIDString, requestID).
Str("traceid", spanContext.TraceID().String()).
Str("remote-addr", r.RemoteAddr).
Str("method", r.Method).
Int("status", wrap.Status()).
Str("path", r.URL.Path).
Dur("duration", time.Since(start)).
Int("bytes", wrap.BytesWritten()).
Msg("access-log")
})
}
}
@@ -44,7 +44,7 @@ func Server(opts ...Option) (http.Service, error) {
options.Config.Service.Name+"."+options.Config.App.Name, options.Config.Service.Name+"."+options.Config.App.Name,
version.GetString(), version.GetString(),
), ),
middleware.Logger( colabmiddleware.AccessLog(
options.Logger, options.Logger,
), ),
middleware.ExtractAccountUUID( middleware.ExtractAccountUUID(