diff options
author | James Fargher <proglottis@gmail.com> | 2021-09-29 05:04:52 +0300 |
---|---|---|
committer | James Fargher <proglottis@gmail.com> | 2021-09-29 05:04:52 +0300 |
commit | 068f99baa3a282ce3698e6754a8cb39b4c21c52b (patch) | |
tree | 806f3109535db1dfd88854627ffcbe8906962ac1 /cmd | |
parent | 316a0b8bd61bbf5802fa1d0d277220e63ae681ee (diff) | |
parent | 1d7f00d36d2863713e8a116de33c2626633a60cb (diff) |
Merge branch 'jc-fix-gitaly-logs' into 'master'
Ensure log entries have time formatted as UTC
Closes #3710
See merge request gitlab-org/gitaly!3912
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/gitaly-backup/main.go | 13 | ||||
-rw-r--r-- | cmd/gitaly-wrapper/main.go | 31 |
2 files changed, 24 insertions, 20 deletions
diff --git a/cmd/gitaly-backup/main.go b/cmd/gitaly-backup/main.go index 4d4846563..641fda42c 100644 --- a/cmd/gitaly-backup/main.go +++ b/cmd/gitaly-backup/main.go @@ -6,8 +6,7 @@ import ( "io" "os" - log "github.com/sirupsen/logrus" - glog "gitlab.com/gitlab-org/gitaly/v14/internal/log" + "gitlab.com/gitlab-org/gitaly/v14/internal/log" ) type subcmd interface { @@ -21,19 +20,21 @@ var subcommands = map[string]subcmd{ } func main() { - glog.Configure(glog.Loggers, "", "") + log.Configure(log.Loggers, "", "") + + logger := log.Default() flags := flag.NewFlagSet("gitaly-backup", flag.ExitOnError) _ = flags.Parse(os.Args) if flags.NArg() < 2 { - log.Fatal("missing subcommand") + logger.Fatal("missing subcommand") } subcmdName := flags.Arg(1) subcmd, ok := subcommands[subcmdName] if !ok { - log.Fatalf("unknown subcommand: %q", flags.Arg(1)) + logger.Fatalf("unknown subcommand: %q", flags.Arg(1)) } subcmdFlags := flag.NewFlagSet(subcmdName, flag.ExitOnError) @@ -41,6 +42,6 @@ func main() { _ = subcmdFlags.Parse(flags.Args()[2:]) if err := subcmd.Run(context.Background(), os.Stdin, os.Stdout); err != nil { - log.Fatalf("%s", err) + logger.Fatalf("%s", err) } } diff --git a/cmd/gitaly-wrapper/main.go b/cmd/gitaly-wrapper/main.go index 3fc315b3c..3eeb55ad5 100644 --- a/cmd/gitaly-wrapper/main.go +++ b/cmd/gitaly-wrapper/main.go @@ -23,55 +23,58 @@ const ( ) func main() { + var logFormat string if jsonLogging() { - logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: log.LogTimestampFormat}) + logFormat = "json" } + log.Configure(log.Loggers, logFormat, "") + if len(os.Args) < 2 { logrus.Fatalf("usage: %s forking_binary [args]", os.Args[0]) } gitalyBin, gitalyArgs := os.Args[1], os.Args[2:] - log := logrus.WithField("wrapper", os.Getpid()) - log.Info("Wrapper started") + logger := log.Default().WithField("wrapper", os.Getpid()) + logger.Info("Wrapper started") if pidFile() == "" { - log.Fatalf("missing pid file ENV variable %q", bootstrap.EnvPidFile) + logger.Fatalf("missing pid file ENV variable %q", bootstrap.EnvPidFile) } - log.WithField("pid_file", pidFile()).Info("finding gitaly") + logger.WithField("pid_file", pidFile()).Info("finding gitaly") gitaly, err := findGitaly() if err != nil && !isRecoverable(err) { - log.WithError(err).Fatal("find gitaly") + logger.WithError(err).Fatal("find gitaly") } else if err != nil { - log.WithError(err).Error("find gitaly") + logger.WithError(err).Error("find gitaly") } if gitaly != nil && isGitaly(gitaly, gitalyBin) { - log.Info("adopting a process") + logger.Info("adopting a process") } else { - log.Info("spawning a process") + logger.Info("spawning a process") proc, err := spawnGitaly(gitalyBin, gitalyArgs) if err != nil { - log.WithError(err).Fatal("spawn gitaly") + logger.WithError(err).Fatal("spawn gitaly") } gitaly = proc } - log = log.WithField("gitaly", gitaly.Pid) - log.Info("monitoring gitaly") + logger = logger.WithField("gitaly", gitaly.Pid) + logger.Info("monitoring gitaly") - forwardSignals(gitaly, log) + forwardSignals(gitaly, logger) // wait for isAlive(gitaly) { time.Sleep(1 * time.Second) } - log.Error("wrapper for gitaly shutting down") + logger.Error("wrapper for gitaly shutting down") } func isRecoverable(err error) bool { |