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:
Keepers 2023-02-02 13:34:53 -07:00 committed by GitHub
parent 844dcae9b6
commit a3aa3bcad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

3
.gitignore vendored
View File

@ -20,6 +20,9 @@
.corso_test.toml
.corso.toml
# Logging
.corso.log
# Build directories
/bin
/docker/bin

View File

@ -8,6 +8,7 @@ import (
"github.com/alcionai/clues"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"github.com/alcionai/corso/src/cli/backup"
"github.com/alcionai/corso/src/cli/config"
@ -51,6 +52,13 @@ func preRun(cc *cobra.Command, args []string) error {
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())
return nil

View File

@ -29,6 +29,8 @@ var (
DebugAPI bool
readableOutput bool
LogFile string
)
type logLevel int
@ -118,6 +120,7 @@ func PreloadLoggingFlags() (string, string) {
}
if logfile != "stdout" && logfile != "stderr" {
LogFile = logfile
logdir := filepath.Dir(logfile)
print.Info(context.Background(), "Logging to file: "+logfile)