Replaced loggers in `internal/` with custom shared logger

pull/1175/head
Kai Lee 6 years ago
parent 109b1da9a7
commit 96cdd552e7
  1. 5
      internal/hmyapi/private_account.go
  2. 7
      internal/hmyapi/util.go
  3. 16
      internal/utils/utils.go

@ -4,10 +4,11 @@ import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/accounts"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/hmy"
"github.com/harmony-one/harmony/internal/utils"
)
// PrivateAccountAPI provides an API to access accounts managed by this node.
@ -37,7 +38,7 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
}
signed, err := s.signTransaction(ctx, &args, passwd)
if err != nil {
log.Warn("Failed transaction send attempt", "from", args.From, "to", args.To, "value", args.Value.ToInt(), "err", err)
utils.GetLogger().Warn("Failed transaction send attempt", "from", args.From, "to", args.To, "value", args.Value.ToInt(), "err", err)
return common.Hash{}, err
}
return SubmitTransaction(ctx, s.b, signed)

@ -5,9 +5,10 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/core/types"
common2 "github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/utils"
)
// SubmitTransaction is a helper function that submits tx to txPool and logs a message.
@ -22,9 +23,9 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
return common.Hash{}, err
}
addr := crypto.CreateAddress(from, tx.Nonce())
log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", common2.MustAddressToBech32(addr))
utils.GetLogger().Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", common2.MustAddressToBech32(addr))
} else {
log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
utils.GetLogger().Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
}
return tx.Hash(), nil
}

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
mrand "math/rand"
"net"
"os"
@ -64,7 +63,8 @@ func ConvertFixedDataIntoByteArray(data interface{}) []byte {
buff := new(bytes.Buffer)
err := binary.Write(buff, binary.BigEndian, data)
if err != nil {
log.Panic(err)
GetLogger().Crit("Failed to convert fixed data into byte array", "err", err)
panic(err)
}
return buff.Bytes()
}
@ -73,7 +73,8 @@ func ConvertFixedDataIntoByteArray(data interface{}) []byte {
func GetUniqueIDFromIPPort(ip, port string) uint32 {
reg, err := regexp.Compile("[^0-9]+")
if err != nil {
log.Panic("Regex Compilation Failed", "err", err)
GetLogger().Crit("Regex Compilation Failed", "err", err)
panic(err)
}
socketID := reg.ReplaceAllString(ip+port, "") // A integer Id formed by unique IP/PORT pair
value, _ := strconv.Atoi(socketID)
@ -199,15 +200,16 @@ func LoadKeyFromFile(keyfile string) (key p2p_crypto.PrivKey, pk p2p_crypto.PubK
var keyStruct PrivKeyStore
err = Load(keyfile, &keyStruct)
if err != nil {
log.Print("No priviate key can be loaded from file", "keyfile", keyfile)
log.Print("Using random private key")
GetLogger().Info("No priviate key can be loaded from file", "keyfile", keyfile)
GetLogger().Info("Using random private key")
key, pk, err = GenKeyP2PRand()
if err != nil {
log.Panic("LoadKeyFromFile", "GenKeyP2PRand Error", err)
GetLogger().Crit("LoadKeyFromFile", "GenKeyP2PRand Error", err)
panic(err)
}
err = SaveKeyToFile(keyfile, key)
if err != nil {
log.Print("LoadKeyFromFile", "failed to save key to keyfile", err)
GetLogger().Error("failed to save key to keyfile", "keyfile", err)
}
return key, pk, nil
}

Loading…
Cancel
Save