Skip to content

Commit

Permalink
Fix plugin logging missing context fields
Browse files Browse the repository at this point in the history
Fix an issue where context fields logged by server on behalf of plugins didn't contain correct name/value pairs:
- bump Logr version to add key/value methods to sugar logger
- expose factory args when configuring logging with custom target types (needed for FocalBoard to create log target adapter that converts typed fields into slices of interface{} as per plugin logging API)
  • Loading branch information
wiggin77 committed Sep 13, 2021
1 parent 17fe158 commit bb659d0
Show file tree
Hide file tree
Showing 53 changed files with 237 additions and 3,702 deletions.
2 changes: 1 addition & 1 deletion api4/apitestlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent

testLogger, _ := mlog.NewLogger()
logCfg, _ := config.MloggerConfigFromLoggerConfig(&memoryConfig.LogSettings, nil, config.GetLogFileLocation)
if errCfg := testLogger.ConfigureTargets(logCfg); errCfg != nil {
if errCfg := testLogger.ConfigureTargets(logCfg, nil); errCfg != nil {
panic("failed to configure test logger: " + errCfg.Error())
}
// lock logger config so server init cannot override it during testing.
Expand Down
2 changes: 1 addition & 1 deletion app/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo

testLogger, _ := mlog.NewLogger()
logCfg, _ := config.MloggerConfigFromLoggerConfig(&memoryConfig.LogSettings, nil, config.GetLogFileLocation)
if errCfg := testLogger.ConfigureTargets(logCfg); errCfg != nil {
if errCfg := testLogger.ConfigureTargets(logCfg, nil); errCfg != nil {
panic("failed to configure test logger: " + errCfg.Error())
}
if errW := mlog.AddWriterTarget(testLogger, buffer, true, mlog.StdAll...); errW != nil {
Expand Down
8 changes: 4 additions & 4 deletions app/plugin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,16 +889,16 @@ func (api *PluginAPI) HasPermissionToChannel(userID, channelID string, permissio
}

func (api *PluginAPI) LogDebug(msg string, keyValuePairs ...interface{}) {
api.logger.Debug(msg, keyValuePairs...)
api.logger.Debugw(msg, keyValuePairs...)
}
func (api *PluginAPI) LogInfo(msg string, keyValuePairs ...interface{}) {
api.logger.Info(msg, keyValuePairs...)
api.logger.Infow(msg, keyValuePairs...)
}
func (api *PluginAPI) LogError(msg string, keyValuePairs ...interface{}) {
api.logger.Error(msg, keyValuePairs...)
api.logger.Errorw(msg, keyValuePairs...)
}
func (api *PluginAPI) LogWarn(msg string, keyValuePairs ...interface{}) {
api.logger.Warn(msg, keyValuePairs...)
api.logger.Warnw(msg, keyValuePairs...)
}

func (api *PluginAPI) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
Expand Down
2 changes: 1 addition & 1 deletion app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ func (s *Server) configureLogger(name string, logger *mlog.Logger, logSettings *
return fmt.Errorf("invalid config source for %s, %w", name, err)
}

if err := logger.ConfigureTargets(cfg); err != nil {
if err := logger.ConfigureTargets(cfg, nil); err != nil {
return fmt.Errorf("invalid config for %s, %w", name, err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func TestPanicLog(t *testing.T) {

cfg, err := config.MloggerConfigFromLoggerConfig(logSettings, nil, config.GetLogFileLocation)
require.NoError(t, err)
err = logger.ConfigureTargets(cfg)
err = logger.ConfigureTargets(cfg, nil)
require.NoError(t, err)
logger.LockConfiguration()

Expand Down
2 changes: 1 addition & 1 deletion app/slashcommands/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo

testLogger, _ := mlog.NewLogger()
logCfg, _ := config.MloggerConfigFromLoggerConfig(&memoryConfig.LogSettings, nil, config.GetLogFileLocation)
if errCfg := testLogger.ConfigureTargets(logCfg); errCfg != nil {
if errCfg := testLogger.ConfigureTargets(logCfg, nil); errCfg != nil {
panic("failed to configure test logger: " + errCfg.Error())
}
// lock logger config so server init cannot override it during testing.
Expand Down
2 changes: 1 addition & 1 deletion audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (a *Audit) Log(level mlog.Level, path string, evt string, status string, us

// Configure sets zero or more target to output audit logs to.
func (a *Audit) Configure(cfg mlog.LoggerConfiguration) error {
return a.logger.ConfigureTargets(cfg)
return a.logger.ConfigureTargets(cfg, nil)
}

// Flush attempts to write all queued audit records to all targets.
Expand Down
12 changes: 2 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/blevesearch/bleve v1.0.14
github.com/cespare/xxhash/v2 v2.1.1
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
github.com/corpix/uarand v0.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dgryski/dgoogauth v0.0.0-20190221195224-5a805980a5f3
github.com/disintegration/imaging v1.6.2
Expand Down Expand Up @@ -56,7 +54,6 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/memberlist v0.2.4
github.com/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864 // indirect
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
github.com/jmoiron/sqlx v1.3.4
github.com/jonboulle/clockwork v0.2.2
Expand All @@ -72,8 +69,7 @@ require (
github.com/mattermost/gosaml2 v0.3.3
github.com/mattermost/gziphandler v0.0.1
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d
github.com/mattermost/logr v1.0.13 // indirect
github.com/mattermost/logr/v2 v2.0.10
github.com/mattermost/logr/v2 v2.0.15
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
Expand Down Expand Up @@ -103,7 +99,6 @@ require (
github.com/russellhaering/goxmldsig v1.1.0
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/smartystreets/assertions v1.0.0 // indirect
github.com/spf13/cobra v1.1.3
github.com/splitio/go-client/v6 v6.1.0
Expand All @@ -119,15 +114,12 @@ require (
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4
github.com/wiggin77/merror v1.0.3
github.com/wiggin77/srslog v1.0.1 // indirect
github.com/willf/bitset v1.1.11 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c
github.com/yuin/goldmark v1.3.8
go.etcd.io/bbolt v1.3.6 // indirect
go.opentelemetry.io/otel/internal/metric v0.21.0 // indirect
go.uber.org/atomic v1.8.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/image v0.0.0-20210622092929-e6eecd499c2c
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
Expand All @@ -139,9 +131,9 @@ require (
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/mail.v2 v2.3.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/olivere/elastic.v6 v6.2.35
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
willnorris.com/go/imageproxy v0.10.0
)

Expand Down
Loading

0 comments on commit bb659d0

Please sign in to comment.