Skip to content

Commit

Permalink
Remove data/time from logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed May 22, 2023
1 parent 7f8887b commit 3ec8f17
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var initCmd = &cobra.Command{
Use: "init",
Short: "Create or overwrite the GatewayD global config",
Run: func(cmd *cobra.Command, args []string) {
logger := log.New(cmd.OutOrStdout(), "", 0)

// Create a new config object and load the defaults.
conf := &config.Config{
GlobalKoanf: koanf.New("."),
Expand All @@ -30,27 +32,27 @@ var initCmd = &cobra.Command{
// Marshal the global config to YAML.
globalCfg, err := conf.GlobalKoanf.Marshal(yaml.Parser())
if err != nil {
log.Fatal(err)
logger.Fatal(err)
}

// Check if the config file already exists and if we should overwrite it.
exists := false
if _, err := os.Stat(globalConfigFile); err == nil && !force {
log.Fatal("Config file already exists. Use --force to overwrite.")
logger.Fatal("Config file already exists. Use --force to overwrite.")
} else if err == nil {
exists = true
}

// Create or overwrite the global config file.
if err := os.WriteFile(globalConfigFile, globalCfg, filePermissions); err != nil {
log.Fatal(err)
logger.Fatal(err)
}

verb := "created"
if exists && force {
verb = "overwritten"
}
log.Printf("Config file '%s' was %s successfully.", globalConfigFile, verb)
logger.Printf("Config file '%s' was %s successfully.", globalConfigFile, verb)
},
}

Expand Down

0 comments on commit 3ec8f17

Please sign in to comment.