Skip to content

Commit

Permalink
Move logs to a subfolder (#4846)
Browse files Browse the repository at this point in the history
  • Loading branch information
d8660091 authored Feb 9, 2023
1 parent f7464f3 commit afc0cab
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/eksctl-anywhere/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -44,8 +45,14 @@ func rootPersistentPreRun(cmd *cobra.Command, args []string) {
}

func initLogger() error {
outputFilePath := fmt.Sprintf("./eksa-cli-%s.log", time.Now().Format("2006-01-02T15_04_05"))
if err := logger.InitZap(logger.ZapOpts{
logsFolder := filepath.Join(".", "eksa-cli-logs")
err := os.MkdirAll(logsFolder, 0o750)
if err != nil {
return fmt.Errorf("failed to create logs folder: %v", err)
}

outputFilePath := filepath.Join(".", "eksa-cli-logs", fmt.Sprintf("%s.log", time.Now().Format("2006-01-02T15_04_05")))
if err = logger.InitZap(logger.ZapOpts{
Level: viper.GetInt("verbosity"),
OutputFilePath: outputFilePath,
}); err != nil {
Expand Down

0 comments on commit afc0cab

Please sign in to comment.