From 686c2fbab7607d42183ae685a27ea3d7dce8c3f6 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 27 Apr 2018 12:49:45 -0700 Subject: Structured logging (#8673) * Implementing structured logging * Changes to en.json to allow refactor to run. * Fixing global logger * Structured logger initalization. * Add caller. * Do some log redirection. * Auto refactor * Cleaning up l4g reference and removing dependancy. * Removing junk. * Copyright headers. * Fixing tests * Revert "Changes to en.json to allow refactor to run." This reverts commit fd8249e99bcad0231e6ea65cd77c32aae9a54026. * Fixing some auto refactor strangeness and typo. * Making keys more human readable. --- cmd/commands/command.go | 1 + cmd/commands/config_flag_test.go | 1 + cmd/commands/jobserver.go | 9 ++++----- cmd/commands/server.go | 27 ++++++++++++++------------- cmd/commands/user.go | 3 +-- cmd/init.go | 2 -- 6 files changed, 21 insertions(+), 22 deletions(-) (limited to 'cmd') diff --git a/cmd/commands/command.go b/cmd/commands/command.go index 380816644..e7b7e0a0d 100644 --- a/cmd/commands/command.go +++ b/cmd/commands/command.go @@ -5,6 +5,7 @@ package commands import ( "errors" + "github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/cmd" "github.com/mattermost/mattermost-server/model" diff --git a/cmd/commands/config_flag_test.go b/cmd/commands/config_flag_test.go index f31c989d8..59178b620 100644 --- a/cmd/commands/config_flag_test.go +++ b/cmd/commands/config_flag_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "encoding/json" + "github.com/mattermost/mattermost-server/cmd" "github.com/mattermost/mattermost-server/utils" ) diff --git a/cmd/commands/jobserver.go b/cmd/commands/jobserver.go index b96984b41..a7671e190 100644 --- a/cmd/commands/jobserver.go +++ b/cmd/commands/jobserver.go @@ -8,8 +8,8 @@ import ( "os/signal" "syscall" - l4g "github.com/alecthomas/log4go" "github.com/mattermost/mattermost-server/cmd" + "github.com/mattermost/mattermost-server/mlog" "github.com/spf13/cobra" ) @@ -36,13 +36,12 @@ func jobserverCmdF(command *cobra.Command, args []string) { if err != nil { panic(err.Error()) } - defer l4g.Close() defer a.Shutdown() a.LoadLicense() // Run jobs - l4g.Info("Starting Mattermost job server") + mlog.Info("Starting Mattermost job server") if !noJobs { a.Jobs.StartWorkers() } @@ -55,10 +54,10 @@ func jobserverCmdF(command *cobra.Command, args []string) { <-signalChan // Cleanup anything that isn't handled by a defer statement - l4g.Info("Stopping Mattermost job server") + mlog.Info("Stopping Mattermost job server") a.Jobs.StopSchedulers() a.Jobs.StopWorkers() - l4g.Info("Stopped Mattermost job server") + mlog.Info("Stopped Mattermost job server") } diff --git a/cmd/commands/server.go b/cmd/commands/server.go index 9048696ca..77f195f4b 100644 --- a/cmd/commands/server.go +++ b/cmd/commands/server.go @@ -4,18 +4,19 @@ package commands import ( + "fmt" "net" "os" "os/signal" "syscall" "time" - l4g "github.com/alecthomas/log4go" "github.com/mattermost/mattermost-server/api" "github.com/mattermost/mattermost-server/api4" "github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/cmd" "github.com/mattermost/mattermost-server/manualtesting" + "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" "github.com/mattermost/mattermost-server/web" @@ -61,7 +62,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan a, err := app.New(options...) if err != nil { - l4g.Critical(err.Error()) + mlog.Critical(err.Error()) return err } defer a.Shutdown() @@ -69,17 +70,17 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan utils.TestConnection(a.Config()) pwd, _ := os.Getwd() - l4g.Info(utils.T("mattermost.current_version"), model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise) - l4g.Info(utils.T("mattermost.entreprise_enabled"), model.BuildEnterpriseReady) - l4g.Info(utils.T("mattermost.working_dir"), pwd) - l4g.Info(utils.T("mattermost.config_file"), utils.FindConfigFile(configFileLocation)) + mlog.Info(fmt.Sprintf("Current version is %v (%v/%v/%v/%v)", model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise)) + mlog.Info(fmt.Sprintf("Enterprise Enabled: %v", model.BuildEnterpriseReady)) + mlog.Info(fmt.Sprintf("Current working directory is %v", pwd)) + mlog.Info(fmt.Sprintf("Loaded config file from %v", utils.FindConfigFile(configFileLocation))) backend, appErr := a.FileBackend() if appErr == nil { appErr = backend.TestConnection() } if appErr != nil { - l4g.Error("Problem with file storage settings: " + appErr.Error()) + mlog.Error("Problem with file storage settings: " + appErr.Error()) } if model.BuildEnterpriseReady == "true" { @@ -99,7 +100,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan serverErr := a.StartServer() if serverErr != nil { - l4g.Critical(serverErr.Error()) + mlog.Critical(serverErr.Error()) return serverErr } @@ -111,7 +112,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan license := a.License() if license == nil && len(a.Config().SqlSettings.DataSourceReplicas) > 1 { - l4g.Warn(utils.T("store.sql.read_replicas_not_licensed.critical")) + mlog.Warn("More than 1 read replica functionality disabled by current license. Please contact your system administrator about upgrading your enterprise license.") a.UpdateConfig(func(cfg *model.Config) { cfg.SqlSettings.DataSourceReplicas = cfg.SqlSettings.DataSourceReplicas[:1] }) @@ -171,7 +172,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan if a.Elasticsearch != nil { a.Go(func() { if err := a.Elasticsearch.Start(); err != nil { - l4g.Error(err.Error()) + mlog.Error(err.Error()) } }) } @@ -241,7 +242,7 @@ func runSessionCleanupJob(a *app.App) { func resetStatuses(a *app.App) { if result := <-a.Srv.Store.Status().ResetAll(); result.Err != nil { - l4g.Error(utils.T("mattermost.reset_status.error"), result.Err.Error()) + mlog.Error(fmt.Sprint("mattermost.reset_status.error FIXME: NOT FOUND IN TRANSLATIONS FILE", result.Err.Error())) } } @@ -260,11 +261,11 @@ func notifyReady() { // notify systemd that the server is ready. systemdSocket := os.Getenv("NOTIFY_SOCKET") if systemdSocket != "" { - l4g.Info("Sending systemd READY notification.") + mlog.Info("Sending systemd READY notification.") err := sendSystemdReadyNotification(systemdSocket) if err != nil { - l4g.Error(err.Error()) + mlog.Error(err.Error()) } } } diff --git a/cmd/commands/user.go b/cmd/commands/user.go index 96e8698e5..da3fb454b 100644 --- a/cmd/commands/user.go +++ b/cmd/commands/user.go @@ -9,7 +9,6 @@ import ( "fmt" "io/ioutil" - l4g "github.com/alecthomas/log4go" "github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/cmd" "github.com/mattermost/mattermost-server/model" @@ -644,7 +643,7 @@ func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error { if err := migrate.MigrateToSaml(fromAuth, matches, autoFlag, dryRunFlag); err != nil { return errors.New("Error while migrating users: " + err.Error()) } - l4g.Close() + cmd.CommandPrettyPrintln("Successfully migrated accounts.") } diff --git a/cmd/init.go b/cmd/init.go index c85bd5362..e3b4e97e1 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -33,8 +33,6 @@ func InitDBCommandContext(configFileLocation string) (*app.App, error) { } model.AppErrorInit(utils.T) - utils.ConfigureCmdLineLog() - a, err := app.New(app.ConfigFile(configFileLocation)) if err != nil { return nil, err -- cgit v1.2.3-1-g7c22