Skip to content

Commit 82fccb6

Browse files
authored
apps: log simplified user agent and downgrade user errors to warn (#5113)
1 parent 083540b commit 82fccb6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

changelog/unreleased/app-agent-log.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Enhancement: log simplified user agent in apps
2+
3+
https://github.com/cs3org/reva/pull/5113

internal/http/services/appprovider/appprovider.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"net/http"
2727
"path"
2828
"path/filepath"
29+
"strings"
2930

3031
apppb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
3132
appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
@@ -436,8 +437,25 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
436437
return
437438
}
438439

440+
var agent string
441+
switch {
442+
case strings.Contains(r.UserAgent(), "Firefox"):
443+
agent = "Firefox"
444+
case strings.Contains(r.UserAgent(), "Chrome"):
445+
agent = "Chrome"
446+
case strings.Contains(r.UserAgent(), "Safari"):
447+
agent = "Safari"
448+
default:
449+
agent = "Other"
450+
}
439451
log := appctx.GetLogger(ctx)
440-
log.Info().Interface("resource", fileRef).Str("url", openRes.AppUrl.AppUrl).Str("method", openRes.AppUrl.Method).Interface("viewMode", viewMode).Str("fileExt", filepath.Ext(statRes.Info.Path)).Msg("returning app URL for file")
452+
log.Info().Interface("resource", fileRef).
453+
Str("url", openRes.AppUrl.AppUrl).
454+
Str("method", openRes.AppUrl.Method).
455+
Interface("viewMode", viewMode).
456+
Str("fileExt", filepath.Ext(statRes.Info.Path)).
457+
Str("agent", agent).
458+
Msg("returning app URL for file")
441459

442460
w.Header().Set("Content-Type", "application/json")
443461
if _, err = w.Write(js); err != nil {

internal/http/services/appprovider/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type appError struct {
5656
// writeError handles writing error responses.
5757
func writeError(w http.ResponseWriter, r *http.Request, code appErrorCode, message string, err error) {
5858
if err != nil {
59-
appctx.GetLogger(r.Context()).Error().Err(err).Msg(message)
59+
appctx.GetLogger(r.Context()).Warn().Err(err).Msg(message)
6060
}
6161

6262
var encoded []byte

0 commit comments

Comments
 (0)