From 7237a370babdc6a5205336aad54a9f843fade8ee Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 28 Apr 2020 01:39:04 +0300 Subject: [PATCH] Implement https://github.com/status-im/nim-beacon-chain/issues/872 Please see the newly added 'schlesi-dev' Makefile target. It demonstrates how the log level can be specified for individual topics. Additionally, when connecting to testnets like 'schlesi' there will be two additional log files produced in the working directory: * json-log.txt * text-log.txt (in the textblocks format) --- Makefile | 3 +++ beacon_chain/beacon_node.nim | 21 +++++++++++++++++---- beacon_chain/conf.nim | 4 ++-- beacon_chain/eth2_network.nim | 5 +++++ scripts/connect_to_testnet.nims | 4 ++-- vendor/nim-chronicles | 2 +- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 255b7d929..1bafc7250 100644 --- a/Makefile +++ b/Makefile @@ -129,6 +129,9 @@ testnet0 testnet1: | build deps schlesi: | build deps LOG_LEVEL="DEBUG" $(ENV_SCRIPT) nim $(NIM_PARAMS) scripts/connect_to_testnet.nims $(SCRIPT_PARAMS) shared/schlesi +schlesi-dev: | build deps + LOG_LEVEL="DEBUG;TRACE:discv5,networking;REQUIRED:none" $(ENV_SCRIPT) nim $(NIM_PARAMS) scripts/connect_to_testnet.nims $(SCRIPT_PARAMS) shared/schlesi + clean: | clean-common rm -rf build/{$(TOOLS_CSV),all_tests,*_node,*ssz*,beacon_node_testnet*,state_sim,transition*} ifneq ($(USE_LIBBACKTRACE), 0) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 2f7b2ea3f..b7293ca1d 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -7,11 +7,12 @@ import # Standard library - os, tables, random, strutils, times, + os, tables, random, strutils, times, sequtils, # Nimble packages stew/[objects, bitseqs, byteutils], stew/shims/macros, - chronos, chronicles, confutils, metrics, json_rpc/[rpcserver, jsonmarshal], + chronos, confutils, metrics, json_rpc/[rpcserver, jsonmarshal], + chronicles, chronicles/helpers as chroniclesHelpers, json_serialization/std/[options, sets, net], serialization/errors, eth/db/kvstore, eth/db/kvstore_sqlite3, eth/p2p/enode, eth/[keys, async_utils], eth/p2p/discoveryv5/[protocol, enr], @@ -1334,8 +1335,20 @@ programMain: randomize() - if config.logLevel != LogLevel.NONE: - setLogLevel(config.logLevel) + try: + let directives = config.logLevel.split(";") + try: + setLogLevel(parseEnum[LogLevel](directives[0])) + except CatchableError: + raise (ref ValueError)(msg: "Please specify one of TRACE, DEBUG, INFO, NOTICE, WARN, ERROR or FATAL") + + if directives.len > 1: + for topicName, settings in parseTopicDirectives(directives[1..^1]): + if not setTopicState(topicName, settings.state, settings.logLevel): + warn "Unrecognized logging topic", topic = topicName + except CatchableError as err: + stderr.write "Invalid value for --log-level. " & err.msg + quit 1 ## Ctrl+C handling proc controlCHandler() {.noconv.} = diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index 7d6c6214e..5f2b88f5e 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -32,9 +32,9 @@ type BeaconNodeConf* = object logLevel* {. - defaultValue: LogLevel.DEBUG + defaultValue: "DEBUG" desc: "Sets the log level." - name: "log-level" }: LogLevel + name: "log-level" }: string eth1Network* {. defaultValue: goerli diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index 468ad1c08..6b9c5207d 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -684,6 +684,11 @@ proc dialPeer*(node: Eth2Node, peerInfo: PeerInfo) {.async.} = var peer = node.getPeer(peerInfo) peer.wasDialed = true + #let msDial = newMultistream() + #let conn = node.switch.connections.getOrDefault(peerInfo.id) + #let ls = await msDial.list(conn) + #debug "Supported protocols", ls + debug "Initializing connection" await initializeConnection(peer) diff --git a/scripts/connect_to_testnet.nims b/scripts/connect_to_testnet.nims index a01e2eb39..1f051d369 100644 --- a/scripts/connect_to_testnet.nims +++ b/scripts/connect_to_testnet.nims @@ -107,7 +107,7 @@ cli do (skipGoerliKey {. rmDir dataDir cd rootDir - exec &"""nim c {nimFlags} -d:"const_preset={preset}" -o:"{beaconNodeBinary}" beacon_chain/beacon_node.nim""" + exec &"""nim c {nimFlags} -d:"const_preset={preset}" -d:"chronicles_sinks=textlines,json[file(json-log.txt)],textblocks[file(text-log.txt)]" -o:"{beaconNodeBinary}" beacon_chain/beacon_node.nim""" mkDir dumpDir @@ -142,7 +142,7 @@ cli do (skipGoerliKey {. let logLevel = getEnv("LOG_LEVEL") var logLevelOpt = "" if logLevel.len > 0: - logLevelOpt = "--log-level=" & logLevel + logLevelOpt = &"""--log-level="{logLevel}" """ mode = Verbose execIgnoringExitCode replace(&"""{beaconNodeBinary} diff --git a/vendor/nim-chronicles b/vendor/nim-chronicles index 9c41783ba..8be157d01 160000 --- a/vendor/nim-chronicles +++ b/vendor/nim-chronicles @@ -1 +1 @@ -Subproject commit 9c41783ba5b16e65f25b09d0e3dadae26dc56707 +Subproject commit 8be157d013be6cafe1ea4afcd5d4192c86fa0a3c