diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2021-10-07 10:07:43 +0000 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2021-10-07 10:07:43 +0000 |
commit | 2ccc5ab15ba57f98a3af70757e24c0a7992b9ac8 (patch) | |
tree | 59fea7221513f43c9ff09afd7ead17f592b72941 /cmd/gitlab-shell | |
parent | 83f76b494051434470f2e6a4c2ebe19a18fc22e8 (diff) | |
parent | e77f0d0603d622d3a2554e55fe62bc1615fca55b (diff) | |
download | gitlab-shell-2ccc5ab15ba57f98a3af70757e24c0a7992b9ac8.tar.gz |
Merge branch '499-log-command-invocation' into 'main'
Log command invocation
See merge request gitlab-org/gitlab-shell!535
Diffstat (limited to 'cmd/gitlab-shell')
-rw-r--r-- | cmd/gitlab-shell/main.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/cmd/gitlab-shell/main.go b/cmd/gitlab-shell/main.go index 2576e8b..a945d0c 100644 --- a/cmd/gitlab-shell/main.go +++ b/cmd/gitlab-shell/main.go @@ -3,6 +3,9 @@ package main import ( "fmt" "os" + "reflect" + + "gitlab.com/gitlab-org/labkit/log" shellCmd "gitlab.com/gitlab-org/gitlab-shell/cmd/gitlab-shell/command" "gitlab.com/gitlab-org/gitlab-shell/internal/command" @@ -62,8 +65,15 @@ func main() { ctx, finished := command.Setup(executable.Name, config) defer finished() - if err = cmd.Execute(ctx); err != nil { + cmdName := reflect.TypeOf(cmd).String() + ctxlog := log.ContextLogger(ctx) + ctxlog.WithFields(log.Fields{"env": env, "command": cmdName}).Info("gitlab-shell: main: executing command") + + if err := cmd.Execute(ctx); err != nil { + ctxlog.WithError(err).Warn("gitlab-shell: main: command execution failed") console.DisplayWarningMessage(err.Error(), readWriter.ErrOut) os.Exit(1) } + + ctxlog.Info("gitlab-shell: main: command executed successfully") } |