Skip to content

Commit cd1f8ca

Browse files
committed
refactor(logs): updated all logs to logrus
1 parent 3ea89f9 commit cd1f8ca

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

cmd/docs.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Copyright © 2022 James Ray [email protected]
55
package cmd
66

77
import (
8-
"log"
9-
8+
log "github.com/sirupsen/logrus"
109
"github.com/spf13/cobra"
1110
"github.com/spf13/cobra/doc"
1211
)
@@ -18,7 +17,7 @@ var docsCmd = &cobra.Command{
1817
Run: func(cmd *cobra.Command, args []string) {
1918
err := doc.GenMarkdownTree(rootCmd, "./docs")
2019
if err != nil {
21-
log.Fatal(err)
20+
log.Fatalln(err)
2221
}
2322
},
2423
}

cmd/init.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66

77
import (
88
"github.com/rayprogramming/toolsium/lib/config"
9+
log "github.com/sirupsen/logrus"
910
"github.com/spf13/cobra"
1011
)
1112

@@ -14,11 +15,16 @@ var initCmd = &cobra.Command{
1415
Use: "init",
1516
Short: "Setup toolsium",
1617
Run: func(cmd *cobra.Command, args []string) {
18+
log.Debugf("init conf path: %v", config.GetConfigFilePath())
1719
err := config.CreateConfig()
1820
cobra.CheckErr(err)
1921
},
2022
}
2123

24+
func runAWS() {
25+
log.Debugln("Done running AWS command")
26+
}
27+
2228
func init() {
2329
rootCmd.AddCommand(initCmd)
2430

cmd/mfa.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ package cmd
77
import (
88
"context"
99
"errors"
10-
"log"
1110

1211
"github.com/aws/aws-sdk-go-v2/aws"
1312
"github.com/aws/aws-sdk-go-v2/config"
1413
"github.com/aws/aws-sdk-go-v2/service/sts"
14+
log "github.com/sirupsen/logrus"
1515
"github.com/spf13/cobra"
1616
"github.com/spf13/viper"
1717
)
@@ -38,7 +38,7 @@ to quickly create a Cobra application.`,
3838
Run: func(cmd *cobra.Command, args []string) {
3939
cfg, err := config.LoadDefaultConfig(context.TODO())
4040
if err != nil {
41-
log.Fatal(err)
41+
log.Fatalln(err)
4242
}
4343

4444
client := sts.NewFromConfig(cfg)
@@ -48,11 +48,11 @@ to quickly create a Cobra application.`,
4848
}
4949
tokenOutput, err := client.GetSessionToken(context.TODO(), &sessionTokenInput)
5050
if err != nil {
51-
log.Fatal(err)
51+
log.Fatalln(err)
5252
}
5353
viper.Set("session", tokenOutput)
5454
if err := viper.WriteConfig(); err != nil {
55-
log.Fatal(err)
55+
log.Fatalln(err)
5656
}
5757
},
5858
}

cmd/papi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ package cmd
77
import (
88
"context"
99
"fmt"
10-
"log"
1110

1211
"github.com/aws/aws-sdk-go-v2/aws"
1312
"github.com/aws/aws-sdk-go-v2/config"
1413
"github.com/aws/aws-sdk-go-v2/service/ec2"
1514
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
1615
"github.com/rayprogramming/toolsium/lib"
16+
log "github.com/sirupsen/logrus"
1717
"github.com/spf13/cobra"
1818
)
1919

@@ -33,7 +33,7 @@ to quickly create a Cobra application.`,
3333
cfg.Credentials = aws.NewCredentialsCache(&lib.MfaProvider{})
3434

3535
if err != nil {
36-
log.Fatal(err)
36+
log.Fatalln(err)
3737
}
3838

3939
client := ec2.NewFromConfig(cfg)

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010

1111
"github.com/rayprogramming/toolsium/lib/config"
12+
log "github.com/sirupsen/logrus"
1213
"github.com/spf13/cobra"
1314
)
1415

@@ -44,5 +45,6 @@ func init() {
4445

4546
// initConfig reads in config file and ENV variables if set.
4647
func initConfig() {
48+
log.Debugf("cfgFile: %v", cfgFile)
4749
config.Configure(cfgFile)
4850
}

lib/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
func Configure(cfgFile string) { t.Configure(cfgFile) }
2020
func (t *Toolsium) Configure(cfgFile string) {
2121
if cfgFile != "" {
22+
log.Debugf("Using custom cfgFile %v", cfgFile)
2223
// Use config file from the flag.
2324
t.Config.SetConfigFile(cfgFile)
2425
} else {
@@ -48,7 +49,7 @@ func (t *Toolsium) GetConfigDir() (path string) {
4849
func SetConfigDir(confDir string) { t.SetConfigDir(confDir) }
4950
func (t *Toolsium) SetConfigDir(confDir string) {
5051
if _, osErr := os.Stat(confDir); os.IsNotExist(osErr) {
51-
log.Infof("Provided config directory didn't exist. %v", confDir)
52+
log.Debugf("Provided config directory didn't exist. %v", confDir)
5253
t.ConfigDir = t.DefaultConfigDirPath()
5354
}
5455
t.ConfigDir = confDir
@@ -98,7 +99,7 @@ func (t *Toolsium) createConfigDirectory() {
9899
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
99100
err := os.Mkdir(path, os.ModePerm)
100101
if err != nil {
101-
log.Errorln(err)
102+
log.Fatalln(err)
102103
}
103104
}
104105
}

0 commit comments

Comments
 (0)