Issue 2329 logfile 1 (#2344)
## Description Prevents showing the log file location when calling commands that defer to help output or env details. Certain cases aren't caught, such as when calling a command with no flags (ex: `corso backup create exchange`). In those cases we catch the lack of flags and manually display the usage within the command handler. ## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change - [x] 🧹 Tech Debt/Cleanup ## Issue(s) * #2329 ## Test Plan - [x] 💪 Manual
This commit is contained in:
parent
844dcae9b6
commit
a3aa3bcad0
3
.gitignore
vendored
3
.gitignore
vendored
@ -20,6 +20,9 @@
|
|||||||
.corso_test.toml
|
.corso_test.toml
|
||||||
.corso.toml
|
.corso.toml
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
.corso.log
|
||||||
|
|
||||||
# Build directories
|
# Build directories
|
||||||
/bin
|
/bin
|
||||||
/docker/bin
|
/docker/bin
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/cli/backup"
|
"github.com/alcionai/corso/src/cli/backup"
|
||||||
"github.com/alcionai/corso/src/cli/config"
|
"github.com/alcionai/corso/src/cli/config"
|
||||||
@ -51,6 +52,13 @@ func preRun(cc *cobra.Command, args []string) error {
|
|||||||
flagSl = append(flagSl, f)
|
flagSl = append(flagSl, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avoidTheseCommands := []string{
|
||||||
|
"corso", "env", "help", "backup", "details", "list", "restore", "delete", "repo", "init", "connect",
|
||||||
|
}
|
||||||
|
if len(logger.LogFile) > 0 && !slices.Contains(avoidTheseCommands, cc.Use) {
|
||||||
|
print.Info(cc.Context(), "Logging to file: "+logger.LogFile)
|
||||||
|
}
|
||||||
|
|
||||||
log.Infow("cli command", "command", cc.CommandPath(), "flags", flagSl, "version", version.CurrentVersion())
|
log.Infow("cli command", "command", cc.CommandPath(), "flags", flagSl, "version", version.CurrentVersion())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -29,6 +29,8 @@ var (
|
|||||||
|
|
||||||
DebugAPI bool
|
DebugAPI bool
|
||||||
readableOutput bool
|
readableOutput bool
|
||||||
|
|
||||||
|
LogFile string
|
||||||
)
|
)
|
||||||
|
|
||||||
type logLevel int
|
type logLevel int
|
||||||
@ -118,6 +120,7 @@ func PreloadLoggingFlags() (string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if logfile != "stdout" && logfile != "stderr" {
|
if logfile != "stdout" && logfile != "stderr" {
|
||||||
|
LogFile = logfile
|
||||||
logdir := filepath.Dir(logfile)
|
logdir := filepath.Dir(logfile)
|
||||||
print.Info(context.Background(), "Logging to file: "+logfile)
|
print.Info(context.Background(), "Logging to file: "+logfile)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user