Add limiting ability to log fields (#24251)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
703ad006ad
Коммит
53a0f8da27
@@ -13,6 +13,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/logr/v2"
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/config"
|
||||
@@ -31,7 +32,7 @@ func (ps *PlatformService) initLogging() error {
|
||||
// create the app logger if needed
|
||||
if ps.logger == nil {
|
||||
var err error
|
||||
ps.logger, err = mlog.NewLogger()
|
||||
ps.logger, err = mlog.NewLogger(logr.MaxFieldLen(*ps.Config().LogSettings.MaxFieldSize))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ require (
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404
|
||||
github.com/mattermost/gziphandler v0.0.1
|
||||
github.com/mattermost/logr/v2 v2.0.16
|
||||
github.com/mattermost/logr/v2 v2.0.18
|
||||
github.com/mattermost/mattermost/server/public v0.0.9
|
||||
github.com/mattermost/morph v1.0.5-0.20230511171014-e76e25978d56
|
||||
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0
|
||||
|
||||
@@ -443,8 +443,8 @@ github.com/mattermost/gziphandler v0.0.1 h1:uXHcXF5agnQ6bXabvpiwwwZOlCYoa7mKHH0l
|
||||
github.com/mattermost/gziphandler v0.0.1/go.mod h1:CvvZR7sXqhj81V2swXuQY7T04Ccc89u7W7pHNPKev8g=
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d h1:/RJ/UV7M5c7L2TQ0KNm4yZxxFvC1nvRz/gY/Daa35aI=
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d/go.mod h1:HLbgMEI5K131jpxGazJ97AxfPDt31osq36YS1oxFQPQ=
|
||||
github.com/mattermost/logr/v2 v2.0.16 h1:jnePX4cPskC3WDFvUardh/xZfxNdsFXbEERJQ1kUEDE=
|
||||
github.com/mattermost/logr/v2 v2.0.16/go.mod h1:1dm/YhTpozsqANXxo5Pi5zYLBsal2xY0pX+JZNbzYJY=
|
||||
github.com/mattermost/logr/v2 v2.0.18 h1:qiznuwwKckZJoGtBYc4Y9FAY97/oQwV1Pq9oO5qP5nk=
|
||||
github.com/mattermost/logr/v2 v2.0.18/go.mod h1:1dm/YhTpozsqANXxo5Pi5zYLBsal2xY0pX+JZNbzYJY=
|
||||
github.com/mattermost/mattermost/server/public v0.0.9 h1:Qsktgxx5dc8xVAUHP5MbSLi6Cf82iB/83r6S9bluHto=
|
||||
github.com/mattermost/mattermost/server/public v0.0.9/go.mod h1:sgXQrYzs+IJy51mB8E8OBljagk2u3YwQRoYlBH5goiw=
|
||||
github.com/mattermost/morph v1.0.5-0.20230511171014-e76e25978d56 h1:SjFYbWvmuf73d/KaYlnHosPpB3/k38ebr1WWw9X5XKc=
|
||||
|
||||
@@ -152,13 +152,12 @@ func (backend *LocalBackend) ServeImage(w http.ResponseWriter, req *http.Request
|
||||
|
||||
resp, err := backend.client.Do(actualReq)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("error fetching remote image: %v", err)
|
||||
mlog.Warn(msg)
|
||||
mlog.Warn("error fetching remote image", mlog.Err(err))
|
||||
statusCode := http.StatusInternalServerError
|
||||
if e, ok := err.(net.Error); ok && e.Timeout() {
|
||||
statusCode = http.StatusGatewayTimeout
|
||||
}
|
||||
http.Error(w, msg, statusCode)
|
||||
http.Error(w, fmt.Sprintf("error fetching remote image: %v", err), statusCode)
|
||||
return
|
||||
}
|
||||
// close the original resp.Body, even if we wrap it in a NopCloser below
|
||||
|
||||
@@ -1276,6 +1276,7 @@ type LogSettings struct {
|
||||
EnableSentry *bool `access:"environment_logging,write_restrictable,cloud_restrictable"` // telemetry: none
|
||||
AdvancedLoggingJSON json.RawMessage `access:"environment_logging,write_restrictable,cloud_restrictable"`
|
||||
AdvancedLoggingConfig *string `access:"environment_logging,write_restrictable,cloud_restrictable"` // Deprecated: use `AdvancedLoggingJSON`
|
||||
MaxFieldSize *int `access:"environment_logging,write_restrictable,cloud_restrictable"`
|
||||
}
|
||||
|
||||
func NewLogSettings() *LogSettings {
|
||||
@@ -1340,6 +1341,10 @@ func (s *LogSettings) SetDefaults() {
|
||||
if s.AdvancedLoggingConfig == nil {
|
||||
s.AdvancedLoggingConfig = NewString("")
|
||||
}
|
||||
|
||||
if s.MaxFieldSize == nil {
|
||||
s.MaxFieldSize = NewInt(2048)
|
||||
}
|
||||
}
|
||||
|
||||
// GetAdvancedLoggingConfig returns the advanced logging config as a []byte.
|
||||
|
||||
Ссылка в новой задаче
Block a user