Skip to content

Commit

Permalink
tail log output for kopia commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-kasten committed Oct 4, 2024
1 parent 33200ed commit 77d528f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pkg/controllers/repositoryserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (h *RepoServerHandler) startRepoProxyServer(ctx context.Context) (err error
Background: true,
},
)

cmd = append([]string{"tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&"}, cmd...)

stdout, stderr, err := kube.Exec(ctx, h.KubeCli, h.RepositoryServer.Namespace, h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, cmd, nil)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr)
Expand Down Expand Up @@ -128,6 +131,7 @@ func (h *RepoServerHandler) createOrUpdateClientUsers(ctx context.Context) error
LogDirectory: command.DefaultLogDirectory,
},
})
cmd = append([]string{"tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&"}, cmd...)
stdout, stderr, err := kube.Exec(ctx, h.KubeCli, h.RepositoryServer.Namespace, h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, cmd, nil)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr)
Expand Down Expand Up @@ -165,6 +169,7 @@ func (h *RepoServerHandler) createOrUpdateClientUsers(ctx context.Context) error
NewUsername: serverUsername,
UserPassword: string(password),
})
cmd = append([]string{"tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&"}, cmd...)
stdout, stderr, err := kube.Exec(ctx, h.KubeCli, h.RepositoryServer.Namespace, h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, cmd, nil)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr)
Expand All @@ -183,6 +188,7 @@ func (h *RepoServerHandler) createOrUpdateClientUsers(ctx context.Context) error
NewUsername: serverUsername,
UserPassword: string(password),
})
cmd = append([]string{"tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&"}, cmd...)
stdout, stderr, err := kube.Exec(ctx, h.KubeCli, h.RepositoryServer.Namespace, h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, cmd, nil)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr)
Expand Down Expand Up @@ -216,6 +222,7 @@ func (h *RepoServerHandler) refreshServer(ctx context.Context) error {
ServerPassword: password,
Fingerprint: fingerprint,
})
cmd = append([]string{"tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&"}, cmd...)
stdout, stderr, err := kube.Exec(ctx, h.KubeCli, h.RepositoryServer.Namespace, h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, cmd, nil)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr)
Expand Down Expand Up @@ -255,5 +262,6 @@ func (h *RepoServerHandler) getServerStatusCommand(ctx context.Context, serverAd
ServerPassword: password,
Fingerprint: fingerprint,
})
cmd = append([]string{"tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&"}, cmd...)
return cmd, nil
}
2 changes: 1 addition & 1 deletion pkg/kopia/cli/internal/opts/common_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
defaultLogLevel = "error"
defaultLogLevel = "debug"
)

// LogDirectory creates a new log directory option with a given directory.
Expand Down
5 changes: 3 additions & 2 deletions pkg/kopia/command/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetEnvOrDefault(name, def string) string {

// LogLevel will return either value from env or "error" as default value
func LogLevel() string {
return GetEnvOrDefault(LogLevelVarName, LogLevelError)
return GetEnvOrDefault(LogLevelVarName, "debug")
}

// FileLogLevel will return value from env
Expand All @@ -61,7 +61,8 @@ type CommandArgs struct {

func bashCommand(args logsafe.Cmd) []string {
log.Info().Print("Kopia Command", field.M{"Command": args.String()})
return []string{"bash", "-o", "errexit", "-c", args.PlainText()}
log.Info().Print("Kopia Running", field.M{"Running": []string{"bash", "-o", "errexit", "-c", "tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&", args.PlainText()}})
return []string{"bash", "-o", "errexit", "-c", "tail", "-v", "-F", "/tmp/kopia-log/cli-logs/latest.log", "&", args.PlainText()}
}

func stringSliceCommand(args logsafe.Cmd) []string {
Expand Down

0 comments on commit 77d528f

Please sign in to comment.