From 83a3ac089cff0d05559e6ba5c2c60b09f5cae176 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 3 Jul 2018 09:58:28 -0700 Subject: MM-11029 Adding plugin logging functionality. (#9034) * Capturing stdout, stderr of plugins in logs. * Cleanup go-plugin debug logs. * Adding logging to plugin API * Generating mocks. * godoc convention --- app/plugin_api.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'app/plugin_api.go') diff --git a/app/plugin_api.go b/app/plugin_api.go index fc786202e..714ffa700 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -7,18 +7,21 @@ import ( "encoding/json" "fmt" + "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" ) type PluginAPI struct { - id string - app *App + id string + app *App + logger *mlog.SugarLogger } func NewPluginAPI(a *App, manifest *model.Manifest) *PluginAPI { return &PluginAPI{ - id: manifest.Id, - app: a, + id: manifest.Id, + app: a, + logger: a.Log.With(mlog.String("plugin_id", manifest.Id)).Sugar(), } } @@ -185,3 +188,16 @@ func (api *PluginAPI) PublishWebSocketEvent(event string, payload map[string]int Broadcast: broadcast, }) } + +func (api *PluginAPI) LogDebug(msg string, keyValuePairs ...interface{}) { + api.logger.Debug(msg, keyValuePairs...) +} +func (api *PluginAPI) LogInfo(msg string, keyValuePairs ...interface{}) { + api.logger.Info(msg, keyValuePairs...) +} +func (api *PluginAPI) LogError(msg string, keyValuePairs ...interface{}) { + api.logger.Error(msg, keyValuePairs...) +} +func (api *PluginAPI) LogWarn(msg string, keyValuePairs ...interface{}) { + api.logger.Warn(msg, keyValuePairs...) +} -- cgit v1.2.3-1-g7c22