cmd/{storagenode,storagenode-updater}: add Process name to logs

Now that we have both the storagenode and updater processes running
in a single docker container, we need a way to know which log entry
is logged by any of the processes.

This change includes a Process field in the log entries.

Resolves https://github.com/storj/storj/issues/4648

Change-Id: I167b9ab65728a41136d264b5fe2c41bb64ed1785
This commit is contained in:
Clement Sam 2022-04-11 03:40:46 +00:00 committed by JT Olio
parent 623cb16b6e
commit e9611801ad
4 changed files with 19 additions and 6 deletions

View File

@ -152,6 +152,6 @@ func openLog(logPath string) error {
return err
}
zap.ReplaceGlobals(logger)
zap.ReplaceGlobals(logger.With(zap.String("Process", updaterServiceName)))
return nil
}

View File

@ -104,10 +104,10 @@ func TestAutoUpdater(t *testing.T) {
if assert.NoError(t, logErr) {
logStr := string(logData)
t.Log(logStr)
if !assert.Contains(t, logStr, `Service restarted successfully. {"Service": "storagenode"}`) {
if !assert.Contains(t, logStr, `Service restarted successfully. {"Process": "storagenode-updater", "Service": "storagenode"}`) {
t.Log(logStr)
}
if !assert.Contains(t, logStr, `Service restarted successfully. {"Service": "storagenode-updater"}`) {
if !assert.Contains(t, logStr, `Service restarted successfully. {"Process": "storagenode-updater", "Service": "storagenode-updater"}`) {
t.Log(logStr)
}
} else {

View File

@ -6,8 +6,16 @@
package main
import "storj.io/private/process"
import (
"go.uber.org/zap"
"storj.io/private/process"
)
func main() {
process.Exec(rootCmd)
loggerFunc := func(logger *zap.Logger) *zap.Logger {
return logger.With(zap.String("Process", updaterServiceName))
}
process.ExecWithCustomConfigAndLogger(rootCmd, true, process.LoadConfig, loggerFunc)
}

View File

@ -471,5 +471,10 @@ func main() {
if startAsService() {
return
}
process.ExecCustomDebug(rootCmd)
loggerFunc := func(logger *zap.Logger) *zap.Logger {
return logger.With(zap.String("Process", rootCmd.Use))
}
process.ExecWithCustomConfigAndLogger(rootCmd, false, process.LoadConfig, loggerFunc)
}