[rpc] add hmy_setLogVerbosity

pull/844/head
Peter Chung 6 years ago
parent b632fd277a
commit d157dd2730
  1. 4
      cmd/harmony/main.go
  2. 5
      internal/hmyapi/backend.go
  3. 33
      internal/hmyapi/debug.go

@ -117,8 +117,8 @@ func initSetup() {
}
// Logging setup
utils.SetPortAndIP(*port, *ip)
utils.SetVerbosity(log.Lvl(*verbosity))
utils.SetLogContext(*port, *ip)
utils.SetLogVerbosity(log.Lvl(*verbosity))
// Set default keystore Dir
hmykey.DefaultKeyStoreDir = *keystoreDir

@ -30,6 +30,11 @@ func GetAPIs(b *core.HmyAPIBackend) []rpc.API {
Version: "1.0",
Service: NewPublicAccountAPI(b.AccountManager()),
Public: true,
}, {
Namespace: "hmy",
Version: "1.0",
Service: NewDebugAPI(b),
Public: true, // FIXME: change to false once IPC implemented
},
}
}

@ -0,0 +1,33 @@
package hmyapi
import (
"context"
"errors"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/internal/utils"
)
// DebugAPI Internal JSON RPC for debugging purpose
type DebugAPI struct {
b *core.HmyAPIBackend
}
// NewDebugAPI Creates a new DebugAPI instance
func NewDebugAPI(b *core.HmyAPIBackend) *DebugAPI {
return &DebugAPI{b}
}
// SetLogVerbosity Sets log verbosity on runtime
// Example usage:
// curl -H "Content-Type: application/json" -d '{"method":"debug_setLogVerbosity","params":[0],"id":1}' http://localhost:9123
func (*DebugAPI) SetLogVerbosity(ctx context.Context, level int) (map[string]interface{}, error) {
if level < int(log.LvlCrit) || level > int(log.LvlTrace) {
return nil, errors.New("invalid log level")
}
verbosity := log.Lvl(level)
utils.SetLogVerbosity(verbosity)
return map[string]interface{}{"verbosity": verbosity.String()}, nil
}
Loading…
Cancel
Save