Merge pull request #557 from LeoHChen/disable_logging_in_wallet

[log] disable logging for wallet
pull/583/head
Leo Chen 6 years ago committed by GitHub
commit 45f7980e8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      api/service/manager.go
  2. 3
      cmd/client/wallet/lib/lib.go
  3. 25
      cmd/client/wallet/main.go

@ -1,7 +1,6 @@
package service package service
import ( import (
"fmt"
"time" "time"
msg_pb "github.com/harmony-one/harmony/api/proto/message" msg_pb "github.com/harmony-one/harmony/api/proto/message"
@ -142,13 +141,10 @@ func (m *Manager) TakeAction(action *Action) {
if service, ok := m.services[action.ServiceType]; ok { if service, ok := m.services[action.ServiceType]; ok {
switch action.Action { switch action.Action {
case Start: case Start:
fmt.Printf("Start %s\n", action.ServiceType)
service.StartService() service.StartService()
case Stop: case Stop:
fmt.Printf("Stop %s\n", action.ServiceType)
service.StopService() service.StopService()
case Notify: case Notify:
fmt.Printf("Notify %s\n", action.ServiceType)
service.NotifyService(action.Params) service.NotifyService(action.Params)
} }
} }

@ -47,6 +47,7 @@ func GetPeersFromBeaconChain(walletNode *node.Node) []p2p.Peer {
peers = append(peers, v.(p2p.Peer)) peers = append(peers, v.(p2p.Peer))
return true return true
}) })
utils.GetLogInstance().Debug("GetPeersFromBeaconChain", "peers:", peers)
return peers return peers
} }
@ -59,8 +60,8 @@ func SubmitTransaction(tx *types.Transaction, walletNode *node.Node, shardID uin
} }
func getBootNodes() []ma.Multiaddr { func getBootNodes() []ma.Multiaddr {
addrStrings := []string{"/ip4/127.0.0.1/tcp/19876/p2p/QmbTLMb9C8dmjrDYoiJb2mayXspcURkNB4ARxgsoA5Aoe3"}
//addrStrings := []string{"/ip4/54.213.43.194/tcp/9874/p2p/QmQhPRqqfTRExqWmTifjMaBvRd3HBmnmj9jYAvTy6HPPJj"} //addrStrings := []string{"/ip4/54.213.43.194/tcp/9874/p2p/QmQhPRqqfTRExqWmTifjMaBvRd3HBmnmj9jYAvTy6HPPJj"}
addrStrings := []string{"/ip4/100.26.90.187/tcp/9871/p2p/QmPH2XsLP88jpfejHycQRWB7vDjwDju9qT9rMmdNaNea5v", "/ip4/54.213.43.194/tcp/9871/p2p/QmQLjTciaJppXVPZFoj4gTdME5axzTxtVwty5Lg8kwt6Zs"}
bootNodeAddrs, err := utils.StringsToAddrs(addrStrings) bootNodeAddrs, err := utils.StringsToAddrs(addrStrings)
if err != nil { if err != nil {
panic(err) panic(err)

@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
crypto2 "github.com/ethereum/go-ethereum/crypto" crypto2 "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
clientService "github.com/harmony-one/harmony/api/client/service" clientService "github.com/harmony-one/harmony/api/client/service"
@ -60,11 +61,16 @@ var (
balanceAddressPtr = balanceCommand.String("address", "", "Specify the account address to check balance for") balanceAddressPtr = balanceCommand.String("address", "", "Specify the account address to check balance for")
) )
// setupLog setup log for verbose output
func setupLog() {
// enable logging for wallet
h := log.StreamHandler(os.Stdout, log.TerminalFormat(false))
log.Root().SetHandler(h)
}
// The main wallet program entrance. Note the this wallet program is for demo-purpose only. It does not implement // The main wallet program entrance. Note the this wallet program is for demo-purpose only. It does not implement
// the secure storage of keys. // the secure storage of keys.
func main() { func main() {
h := log.StreamHandler(os.Stdout, log.TerminalFormat(false))
log.Root().SetHandler(h)
// Verify that a subcommand has been provided // Verify that a subcommand has been provided
// os.Arg[0] is the main command // os.Arg[0] is the main command
@ -90,6 +96,12 @@ func main() {
os.Exit(1) os.Exit(1)
} }
// Enable log if the last parameter is -verbose
if os.Args[len(os.Args)-1] == "--verbose" {
setupLog()
os.Args = os.Args[:len(os.Args)-1]
}
// Switch on the subcommand // Switch on the subcommand
switch os.Args[1] { switch os.Args[1] {
case "-version": case "-version":
@ -310,7 +322,10 @@ func convertBalanceIntoReadableFormat(balance *big.Int) string {
func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]AccountState { func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]AccountState {
result := make(map[uint32]AccountState) result := make(map[uint32]AccountState)
peers := lib.GetPeersFromBeaconChain(walletNode) peers := lib.GetPeersFromBeaconChain(walletNode)
if len(peers) == 0 {
fmt.Printf("[FATAL] Can't find peers\n")
return nil
}
peer := peers[0] peer := peers[0]
port, _ := strconv.Atoi(peer.Port) port, _ := strconv.Atoi(peer.Port)
client := clientService.NewClient(peer.IP, strconv.Itoa(port+node.ClientServicePortDiff)) client := clientService.NewClient(peer.IP, strconv.Itoa(port+node.ClientServicePortDiff))
@ -324,6 +339,10 @@ func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]Acco
// GetFreeToken requests for token test token on each shard // GetFreeToken requests for token test token on each shard
func GetFreeToken(address common.Address, walletNode *node.Node) { func GetFreeToken(address common.Address, walletNode *node.Node) {
peers := lib.GetPeersFromBeaconChain(walletNode) peers := lib.GetPeersFromBeaconChain(walletNode)
if len(peers) == 0 {
fmt.Printf("[FATAL] Can't find peers\n")
return
}
peer := peers[0] peer := peers[0]
port, _ := strconv.Atoi(peer.Port) port, _ := strconv.Atoi(peer.Port)
client := clientService.NewClient(peer.IP, strconv.Itoa(port+node.ClientServicePortDiff)) client := clientService.NewClient(peer.IP, strconv.Itoa(port+node.ClientServicePortDiff))

Loading…
Cancel
Save