[logging] add verbosity flag to bootnode, txgen, harmony cmd

pull/844/head
Peter Chung 6 years ago
parent 8bd2acd7ca
commit 01f69f2e7a
  1. 10
      cmd/bootnode/main.go
  2. 3
      cmd/client/txgen/main.go
  3. 11
      cmd/harmony/main.go
  4. 8
      internal/utils/singleton.go

@ -32,16 +32,16 @@ func printVersion(me string) {
os.Exit(0)
}
func loggingInit(logFolder, ip, port string) {
func loggingInit(logFolder, ip, port string, verbosity log.Lvl) {
// Setup a logger to stdout and log file.
if err := os.MkdirAll(logFolder, 0755); err != nil {
panic(err)
}
logFileName := fmt.Sprintf("./%v/bootnode-%v-%v.log", logFolder, ip, port)
h := log.MultiHandler(
h := log.LvlFilterHandler(verbosity, log.MultiHandler(
log.StreamHandler(os.Stdout, log.TerminalFormat(false)),
log.Must.FileHandler(logFileName, log.JSONFormat()), // Log to file
)
))
log.Root().SetHandler(h)
}
@ -51,6 +51,7 @@ func main() {
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
keyFile := flag.String("key", "./.bnkey", "the private key file of the bootnode")
versionFlag := flag.Bool("version", false, "Output version info")
verbosity := flag.Int("verbosity", 3, "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)")
flag.Parse()
@ -60,9 +61,10 @@ func main() {
// Logging setup
utils.SetPortAndIP(*port, *ip)
utils.SetVerbosity(log.Lvl(*verbosity))
// Init logging.
loggingInit(*logFolder, *ip, *port)
loggingInit(*logFolder, *ip, *port, log.Lvl(*verbosity))
privKey, _, err := utils.LoadKeyFromFile(*keyFile)
if err != nil {

@ -68,6 +68,8 @@ var (
shardIDFlag = flag.Int("shardID", 0, "The shardID the node belongs to.")
// Key file to store the private key
keyFile = flag.String("key", "./.txgenkey", "the private key file of the txgen")
// logging verbosity
verbosity = flag.Int("verbosity", 3, "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)")
)
func setUpTXGen() *node.Node {
@ -127,6 +129,7 @@ func main() {
runtime.GOMAXPROCS(1024)
// Logging setup
utils.SetPortAndIP(*port, *ip)
utils.SetVerbosity(log.Lvl(*verbosity))
if len(utils.BootNodes) == 0 {
bootNodeAddrs, err := utils.StringsToAddrs(utils.DefaultBootNodeAddrStrings)
if err != nil {

@ -58,13 +58,13 @@ func printVersion(me string) {
os.Exit(0)
}
func loggingInit(logFolder, role, ip, port string, onlyLogTps bool) {
func loggingInit(logFolder, role, ip, port string, onlyLogTps bool, verbosity log.Lvl) {
// Setup a logger to stdout and log file.
logFileName := fmt.Sprintf("./%v/%s-%v-%v.log", logFolder, role, ip, port)
h := log.MultiHandler(
h := log.LvlFilterHandler(verbosity, log.MultiHandler(
log.StreamHandler(os.Stdout, log.TerminalFormat(false)),
log.Must.FileHandler(logFileName, log.JSONFormat()), // Log to file
)
))
if onlyLogTps {
h = log.MatchFilterHandler("msg", "TPS Report", h)
}
@ -105,6 +105,8 @@ var (
ks *keystore.KeyStore
myAccount accounts.Account
myPass = ""
// logging verbosity
verbosity = flag.Int("verbosity", 3, "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)")
)
func initSetup() {
@ -114,6 +116,7 @@ func initSetup() {
// Logging setup
utils.SetPortAndIP(*port, *ip)
utils.SetVerbosity(log.Lvl(*verbosity))
// Set default keystore Dir
hmykey.DefaultKeyStoreDir = *keystoreDir
@ -375,7 +378,7 @@ func main() {
nodeConfig := createGlobalConfig()
// Init logging.
loggingInit(*logFolder, nodeConfig.StringRole, *ip, *port, *onlyLogTps)
loggingInit(*logFolder, nodeConfig.StringRole, *ip, *port, *onlyLogTps, log.Lvl(*verbosity))
// Start Profiler for leader if profile argument is on
if nodeConfig.StringRole == "leader" && (*profile || *metricsReportURL != "") {

@ -3,6 +3,7 @@
package utils
import (
"os"
"sync"
"sync/atomic"
@ -13,6 +14,7 @@ import (
var (
Port string
IP string
Verbosity = log.LvlInfo
)
// SetPortAndIP used to print out loggings of node with Port and IP.
@ -22,6 +24,11 @@ func SetPortAndIP(port, ip string) {
IP = ip
}
// SetVerbosity specifies the verbosity of global logger
func SetVerbosity(verbosity log.Lvl) {
Verbosity = verbosity
}
// UniqueValidatorID defines the structure of unique validator ID
type UniqueValidatorID struct {
uniqueID uint32
@ -51,6 +58,7 @@ func (s *UniqueValidatorID) GetUniqueID() uint32 {
func GetLogInstance() log.Logger {
onceForLog.Do(func() {
logInstance = log.New("port", Port, "ip", IP)
logInstance.SetHandler(log.LvlFilterHandler(Verbosity, log.StreamHandler(os.Stdout, log.TerminalFormat(false))))
})
return logInstance
}

Loading…
Cancel
Save