github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/rpc/prysm/v1alpha1/debug/server.go (about) 1 // Package debug defines a gRPC server implementation of a debugging service 2 // which allows for helpful endpoints to debug a beacon node at runtime, this server is 3 // gated behind the feature flag --enable-debug-rpc-endpoints. 4 package debug 5 6 import ( 7 "context" 8 "os" 9 10 gethlog "github.com/ethereum/go-ethereum/log" 11 "github.com/golang/protobuf/ptypes/empty" 12 golog "github.com/ipfs/go-log/v2" 13 "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" 14 "github.com/prysmaticlabs/prysm/beacon-chain/db" 15 "github.com/prysmaticlabs/prysm/beacon-chain/p2p" 16 "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" 17 pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" 18 "github.com/sirupsen/logrus" 19 "google.golang.org/grpc/codes" 20 "google.golang.org/grpc/status" 21 ) 22 23 // Server defines a server implementation of the gRPC Debug service, 24 // providing RPC endpoints for runtime debugging of a node, this server is 25 // gated behind the feature flag --enable-debug-rpc-endpoints. 26 type Server struct { 27 BeaconDB db.NoHeadAccessDatabase 28 GenesisTimeFetcher blockchain.TimeFetcher 29 StateGen *stategen.State 30 HeadFetcher blockchain.HeadFetcher 31 PeerManager p2p.PeerManager 32 PeersFetcher p2p.PeersProvider 33 } 34 35 // SetLoggingLevel of a beacon node according to a request type, 36 // either INFO, DEBUG, or TRACE. 37 func (ds *Server) SetLoggingLevel(_ context.Context, req *pbrpc.LoggingLevelRequest) (*empty.Empty, error) { 38 var verbosity string 39 switch req.Level { 40 case pbrpc.LoggingLevelRequest_INFO: 41 verbosity = "info" 42 case pbrpc.LoggingLevelRequest_DEBUG: 43 verbosity = "debug" 44 case pbrpc.LoggingLevelRequest_TRACE: 45 verbosity = "trace" 46 default: 47 return nil, status.Error(codes.InvalidArgument, "Expected valid verbosity level as argument") 48 } 49 level, err := logrus.ParseLevel(verbosity) 50 if err != nil { 51 return nil, status.Error(codes.Internal, "Could not parse verbosity level") 52 } 53 logrus.SetLevel(level) 54 if level == logrus.TraceLevel { 55 // Libp2p specific logging. 56 golog.SetAllLoggers(golog.LevelDebug) 57 // Geth specific logging. 58 glogger := gethlog.NewGlogHandler(gethlog.StreamHandler(os.Stderr, gethlog.TerminalFormat(true))) 59 glogger.Verbosity(gethlog.LvlTrace) 60 gethlog.Root().SetHandler(glogger) 61 } 62 return &empty.Empty{}, nil 63 }