Skip to content

Commit d109e9d

Browse files
author
harry
authored
[CLI] Remove logging for end user focused messages (#698)
## Description This PR replaces all `logger` instances with `fmt.Print` statements when dealing with information that is intended to be read by the user. It also adds the `verbose` flag to hide config file messages when the user runs a CLI command without it present. And fixes some comment formatting and keybase initialisation for the debug environment. ## Issue Fixes #200 ## Type of change Please mark the relevant option(s): - [ ] New feature, functionality or library - [x] Bug fix - [x] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Replace `logger` calls with `fmt.Print` statements throughout the CLI - Reformat some print statements to have spaces after emojis - Add verbose flag to hide config file messages - Fix keybase initialisation in debug environment ## Testing - [x] `make develop_test`; if any code changes were made - [x] [Docker Compose LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md); if any major functionality was changed or introduced - [x] [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any infrastructure or configuration changes were made ## Required Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added, or updated, [`godoc` format comments](https://go.dev/blog/godoc) on touched members (see: [tip.golang.org/doc/comment](https://tip.golang.org/doc/comment)) - [x] I have tested my changes using the available tooling - [ ] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [ ] I have updated the corresponding README(s); local and/or global - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)
1 parent 9a6cff7 commit d109e9d

File tree

6 files changed

+53
-22
lines changed

6 files changed

+53
-22
lines changed

app/client/cli/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
dataDir string
1919
configPath string
2020
nonInteractive bool
21+
verbose bool
2122
cfg *configs.Config
2223
)
2324

@@ -31,6 +32,11 @@ func init() {
3132
if err := viper.BindPFlag("root_directory", rootCmd.PersistentFlags().Lookup("data_dir")); err != nil {
3233
panic(err)
3334
}
35+
36+
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Show verbose output")
37+
if err := viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")); err != nil {
38+
panic(err)
39+
}
3440
}
3541

3642
var rootCmd = &cobra.Command{

app/client/cli/keys.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strconv"
88
"strings"
99

10-
"github.com/pokt-network/pocket/logger"
1110
"github.com/pokt-network/pocket/shared/codec"
1211
coreTypes "github.com/pokt-network/pocket/shared/core/types"
1312
"github.com/pokt-network/pocket/shared/crypto"
@@ -81,7 +80,7 @@ func keysCreateCommands() []*cobra.Command {
8180
return err
8281
}
8382

84-
logger.Global.Info().Str("address", kp.GetAddressString()).Msg("New Key Created")
83+
fmt.Printf("New key created 🔐: %s\n", kp.GetAddressString())
8584

8685
return nil
8786
},
@@ -129,7 +128,7 @@ func keysUpdateCommands() []*cobra.Command {
129128
return err
130129
}
131130

132-
logger.Global.Info().Str("address", addrHex).Msg("Key updated")
131+
fmt.Printf("Key updated 🔐: %s\n", addrHex)
133132

134133
return nil
135134
},
@@ -176,7 +175,7 @@ func keysDeleteCommands() []*cobra.Command {
176175
return err
177176
}
178177

179-
logger.Global.Info().Str("address", addrHex).Msg("Key deleted")
178+
fmt.Printf("Key deleted ❌: %s\n", addrHex)
180179

181180
return nil
182181
},
@@ -215,7 +214,10 @@ func keysGetCommands() []*cobra.Command {
215214
return err
216215
}
217216

218-
logger.Global.Info().Strs("addresses", addresses).Msg("Get all keys")
217+
fmt.Println("All keys 🔑")
218+
for _, addr := range addresses {
219+
fmt.Println(addr)
220+
}
219221

220222
return nil
221223
},
@@ -244,7 +246,8 @@ func keysGetCommands() []*cobra.Command {
244246
return err
245247
}
246248

247-
logger.Global.Info().Str("address", addrHex).Str("public_key", kp.GetPublicKey().String()).Msg("Found key")
249+
fmt.Println("Key details 🕵️")
250+
fmt.Printf("Address: %s\nPublic Key: %s\n", addrHex, kp.GetPublicKey().String())
248251

249252
return nil
250253
},
@@ -301,11 +304,11 @@ func keysExportCommands() []*cobra.Command {
301304

302305
// Write to stdout or file
303306
if outputFile == "" {
304-
logger.Global.Info().Str("private_key", exportString).Msg("Key exported")
307+
fmt.Printf("Private Key 🔒: %s\n", exportString)
305308
return nil
306309
}
307310

308-
logger.Global.Info().Str("output_file", outputFile).Msg("Exporting private key string to file...")
311+
fmt.Println("Writing private key to file")
309312

310313
return utils.WriteOutput(exportString, outputFile)
311314
},
@@ -380,7 +383,7 @@ func keysImportCommands() []*cobra.Command {
380383
return err
381384
}
382385

383-
logger.Global.Info().Str("address", kp.GetAddressString()).Msg("Key imported")
386+
fmt.Printf("Key imported 📥: %s\n", kp.GetAddressString())
384387

385388
return nil
386389
},
@@ -436,7 +439,7 @@ func keysSignMsgCommands() []*cobra.Command {
436439

437440
sigHex := hex.EncodeToString(sigBz)
438441

439-
logger.Global.Info().Str("signature", sigHex).Str("address", addrHex).Msg("Message signed")
442+
fmt.Printf("Message signed 🔏\nSignature: %s\n", sigHex)
440443

441444
return nil
442445
},
@@ -475,7 +478,12 @@ func keysSignMsgCommands() []*cobra.Command {
475478
return err
476479
}
477480

478-
logger.Global.Info().Str("address", addrHex).Bool("valid", valid).Msg("Signature checked")
481+
if !valid {
482+
fmt.Println("Signature is not valid ❌")
483+
return nil
484+
}
485+
486+
fmt.Println("Signature is valid ✅")
479487

480488
return nil
481489
},
@@ -563,7 +571,7 @@ func keysSignTxCommands() []*cobra.Command {
563571
return err
564572
}
565573

566-
logger.Global.Info().Str("signed_transaction_file", outputFile).Str("address", addrHex).Msg("Message signed")
574+
fmt.Printf("Message signed 🔏\nKey Address: %s\nSignature file: %s\n", addrHex, outputFile)
567575

568576
return nil
569577
},
@@ -627,7 +635,12 @@ func keysSignTxCommands() []*cobra.Command {
627635
return err
628636
}
629637

630-
logger.Global.Info().Str("address", addrHex).Bool("valid", valid).Msg("Signature checked")
638+
if !valid {
639+
fmt.Println("Signature is not valid ❌")
640+
return nil
641+
}
642+
643+
fmt.Println("Signature is valid ✅")
631644

632645
return nil
633646
},
@@ -679,7 +692,10 @@ func keysSlipCommands() []*cobra.Command {
679692
return err
680693
}
681694

682-
logger.Global.Info().Str("address", kp.GetAddressString()).Str("parent", parentAddr).Uint32("index", index).Bool("stored", storeChild).Msg("Child key derived")
695+
fmt.Printf("Child key created 🚸\nChild Address: %s\nParent Address: %s\n", kp.GetAddressString(), parentAddr)
696+
if storeChild {
697+
fmt.Println("Child key stored in the Keybase 🔐")
698+
}
683699

684700
return nil
685701
},

app/client/cli/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"io"
66
"net/http"
7+
"os"
78

8-
"github.com/pokt-network/pocket/logger"
99
"github.com/pokt-network/pocket/rpc"
1010
"github.com/spf13/cobra"
1111
)
@@ -47,7 +47,7 @@ func queryCommands() []*cobra.Command {
4747
statusCode := response.StatusCode
4848
body, err := io.ReadAll(response.Body)
4949
if err != nil {
50-
logger.Global.Error().Err(err).Msg("Error reading response body")
50+
fmt.Fprintf(os.Stderr, "❌ Error reading response body: %s\n", err.Error())
5151
return err
5252
}
5353
if statusCode == http.StatusOK {
0 Bytes
Binary file not shown.

build/debug_keybase/main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/pokt-network/pocket/app/client/keybase"
1313
"github.com/pokt-network/pocket/runtime/configs"
14+
"github.com/pokt-network/pocket/runtime/defaults"
1415
cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
1516
"github.com/pokt-network/pocket/shared/utils"
1617
)
@@ -52,7 +53,7 @@ func main() {
5253
}
5354

5455
func dumpKeybase(privateKeysYamlBytes []byte, targetFilePath string) {
55-
fmt.Println("⚙️ Initializing debug Keybase...")
56+
fmt.Println("⚙️ Initializing debug Keybase...")
5657

5758
validatorKeysPairMap, err := parseValidatorPrivateKeysFromEmbeddedYaml(privateKeysYamlBytes)
5859
if err != nil {
@@ -65,7 +66,9 @@ func dumpKeybase(privateKeysYamlBytes []byte, targetFilePath string) {
6566
}
6667
defer os.RemoveAll(tmpDir)
6768

68-
kb, err := keybase.NewKeybase(&configs.KeybaseConfig{})
69+
kb, err := keybase.NewKeybase(&configs.KeybaseConfig{
70+
FilePath: defaults.DefaultRootDirectory + "/keys",
71+
})
6972
if err != nil {
7073
panic(err)
7174
}
@@ -75,7 +78,7 @@ func dumpKeybase(privateKeysYamlBytes []byte, targetFilePath string) {
7578
}
7679

7780
// Add validator addresses if not present
78-
fmt.Println("✍️ Debug keybase initializing... Adding all the validator keys")
81+
fmt.Println("✍️ Debug keybase initializing... Adding all the validator keys")
7982

8083
// Use writebatch to speed up bulk insert
8184
wb := db.NewWriteBatch()
@@ -128,7 +131,7 @@ func dumpKeybase(privateKeysYamlBytes []byte, targetFilePath string) {
128131

129132
fmt.Println("✅ Keybase initialized!")
130133

131-
fmt.Println("⚙️ Creating a dump of the Keybase...")
134+
fmt.Println("⚙️ Creating a dump of the Keybase...")
132135
backupFile, err := os.Create(targetFilePath)
133136
if err != nil {
134137
panic(err)

runtime/configs/config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,22 @@ func ParseConfig(cfgFile string) *Config {
5151
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
5252
viper.AutomaticEnv()
5353

54+
verbose := viper.GetBool("verbose")
55+
5456
if err := viper.ReadInConfig(); err != nil {
5557
if _, ok := err.(viper.ConfigFileNotFoundError); ok && cfgFile == "" {
56-
log.Default().Printf("No config provided, using defaults")
58+
if verbose {
59+
log.Default().Printf("No config provided, using defaults")
60+
}
5761
} else {
5862
// TODO: This is a log call to avoid import cycles. Refactor logger_config.proto to avoid this.
5963
log.Fatalf("[ERROR] fatal error reading config file %s", err.Error())
6064
}
6165
} else {
6266
// TODO: This is a log call to avoid import cycles. Refactor logger_config.proto to avoid this.
63-
log.Default().Printf("Using config file: %s", viper.ConfigFileUsed())
67+
if verbose {
68+
log.Default().Printf("Using config file: %s", viper.ConfigFileUsed())
69+
}
6470
}
6571

6672
decoderConfig := func(dc *mapstructure.DecoderConfig) {

0 commit comments

Comments
 (0)