server: logger handler (#343)

* Problem: verbose logs display with FATAL option (fix #320)
add my script

increase amount for metamask

add run

amount ok

hide log

show info

my logger

hook log

revive eth log

tidy up

use suplog

log replace ok

removed suplog

tidy up

tidy up

fix compile

remove sh

tidy up

tidy up

* logger handler

* fix

* fix eth log override (#371)

remove redundant log

tidy up

* log test

* c++

Co-authored-by: jongwhan lee <jonghwan@crypto.com>
Co-authored-by: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com>
This commit is contained in:
Federico Kunze Küllmer
2021-08-19 16:55:13 +00:00
committed by GitHub
co-authored by jongwhan lee Jongwhan Lee
parent ea3ec3b7c6
commit d068f5b331
16 changed files with 213 additions and 69 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ import (
// StartJSONRPC starts the JSON-RPC server
func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr string, tmEndpoint string, config config.Config) (*http.Server, chan struct{}, error) {
tmWsClient := ConnectTmWS(tmRPCAddr, tmEndpoint)
tmWsClient := ConnectTmWS(tmRPCAddr, tmEndpoint, ctx.Logger)
rpcServer := ethrpc.NewServer()
@@ -76,7 +76,7 @@ func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr strin
_, port, _ := net.SplitHostPort(config.JSONRPC.Address)
// allocate separate WS connection to Tendermint
tmWsClient = ConnectTmWS(tmRPCAddr, tmEndpoint)
tmWsClient = ConnectTmWS(tmRPCAddr, tmEndpoint, ctx.Logger)
wsSrv := rpc.NewWebsocketsServer(ctx.Logger, tmWsClient, "localhost:"+port, config.JSONRPC.WsAddress)
wsSrv.Start()
return httpSrv, httpSrvDone, nil
+3 -2
View File
@@ -14,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/spf13/cobra"
"google.golang.org/grpc"
abciserver "github.com/tendermint/tendermint/abci/server"
@@ -40,8 +41,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethlog "github.com/ethereum/go-ethereum/log"
ethdebug "github.com/tharsis/ethermint/ethereum/rpc/namespaces/debug"
"github.com/tharsis/ethermint/log"
"github.com/tharsis/ethermint/server/config"
srvflags "github.com/tharsis/ethermint/server/flags"
)
@@ -368,7 +369,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
}
}
ethlog.Root().SetHandler(ethlog.StdoutHandler)
ethlog.Root().SetHandler(log.NewHandler(logger))
var (
httpSrv *http.Server
+16 -7
View File
@@ -7,12 +7,12 @@ import (
"github.com/gorilla/mux"
"github.com/improbable-eng/grpc-web/go/grpcweb"
"github.com/spf13/cobra"
log "github.com/xlab/suplog"
sdkserver "github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/version"
tmlog "github.com/tendermint/tendermint/libs/log"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tharsis/ethermint/app"
@@ -44,22 +44,29 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type
)
}
func ConnectTmWS(tmRPCAddr, tmEndpoint string) *rpcclient.WSClient {
func ConnectTmWS(tmRPCAddr, tmEndpoint string, logger tmlog.Logger) *rpcclient.WSClient {
tmWsClient, err := rpcclient.NewWS(tmRPCAddr, tmEndpoint,
rpcclient.MaxReconnectAttempts(256),
rpcclient.ReadWait(120*time.Second),
rpcclient.WriteWait(120*time.Second),
rpcclient.PingPeriod(50*time.Second),
rpcclient.OnReconnect(func() {
log.WithField("tendermint_rpc", tmRPCAddr+tmEndpoint).
Debugln("EVM RPC reconnects to Tendermint WS")
logger.Debug("EVM RPC reconnects to Tendermint WS", "address", tmRPCAddr+tmEndpoint)
}),
)
if err != nil {
log.WithError(err).Fatalln("Tendermint WS client could not be created for ", tmRPCAddr+tmEndpoint)
logger.Error(
"Tendermint WS client could not be created",
"address", tmRPCAddr+tmEndpoint,
"error", err,
)
} else if err := tmWsClient.OnStart(); err != nil {
log.WithError(err).Fatalln("Tendermint WS client could not start for ", tmRPCAddr+tmEndpoint)
logger.Error(
"Tendermint WS client could not start",
"address", tmRPCAddr+tmEndpoint,
"error", err,
)
}
return tmWsClient
@@ -69,9 +76,11 @@ func MountGRPCWebServices(
router *mux.Router,
grpcWeb *grpcweb.WrappedGrpcServer,
grpcResources []string,
logger tmlog.Logger,
) {
for _, res := range grpcResources {
log.Printf("[GRPC Web] HTTP POST mounted on %s", res)
logger.Info("[GRPC Web] HTTP POST mounted", "resource", res)
s := router.Methods("POST").Subrouter()
s.HandleFunc(res, func(resp http.ResponseWriter, req *http.Request) {