mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-02 17:53:52 +00:00
rpc: setLogLevel (#1991)
* rpc: setLogLevel also change default rpc port to match makefile and manual * set topic-level formats too and make feature less secret
This commit is contained in:
parent
43c6c5a0b3
commit
332e248d91
@ -38,7 +38,7 @@ type
|
|||||||
BeaconNodeConf* = object
|
BeaconNodeConf* = object
|
||||||
logLevel* {.
|
logLevel* {.
|
||||||
defaultValue: "INFO"
|
defaultValue: "INFO"
|
||||||
desc: "Sets the log level"
|
desc: "Sets the log level for process and topics (e.g. \"DEBUG; TRACE:discv5,libp2p; REQUIRED:none; DISABLED:none\")"
|
||||||
name: "log-level" }: string
|
name: "log-level" }: string
|
||||||
|
|
||||||
logFile* {.
|
logFile* {.
|
||||||
|
@ -28,6 +28,19 @@ proc setupStdoutLogging*(logLevel: string) =
|
|||||||
except IOError as err:
|
except IOError as err:
|
||||||
logLoggingFailure(cstring(msg), err)
|
logLoggingFailure(cstring(msg), err)
|
||||||
|
|
||||||
|
proc updateLogLevel*(logLevel: string) =
|
||||||
|
# Updates log levels (without clearing old ones)
|
||||||
|
let directives = logLevel.split(";")
|
||||||
|
try:
|
||||||
|
setLogLevel(parseEnum[LogLevel](directives[0]))
|
||||||
|
except ValueError:
|
||||||
|
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
|
||||||
|
|
||||||
proc setupLogging*(logLevel: string, logFile: Option[OutFile]) =
|
proc setupLogging*(logLevel: string, logFile: Option[OutFile]) =
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
@ -49,16 +62,7 @@ proc setupLogging*(logLevel: string, logFile: Option[OutFile]) =
|
|||||||
warn "The --log-file option is not active in the current build"
|
warn "The --log-file option is not active in the current build"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let directives = logLevel.split(";")
|
updateLogLevel(logLevel)
|
||||||
try:
|
|
||||||
setLogLevel(parseEnum[LogLevel](directives[0]))
|
|
||||||
except ValueError:
|
|
||||||
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 ValueError as err:
|
except ValueError as err:
|
||||||
stderr.write "Invalid value for --log-level. " & err.msg
|
stderr.write "Invalid value for --log-level. " & err.msg
|
||||||
quit 1
|
quit 1
|
||||||
|
@ -10,7 +10,7 @@ import
|
|||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
json_rpc/[rpcserver, jsonmarshal],
|
json_rpc/[rpcserver, jsonmarshal],
|
||||||
|
|
||||||
../beacon_node_common, ../eth2_network,
|
../beacon_node_common, ../nimbus_binary_common, ../eth2_network,
|
||||||
../spec/[digest, datatypes, presets]
|
../spec/[digest, datatypes, presets]
|
||||||
|
|
||||||
logScope: topics = "nimbusapi"
|
logScope: topics = "nimbusapi"
|
||||||
@ -83,3 +83,8 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
|||||||
res.add("peers", peers)
|
res.add("peers", peers)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
rpcServer.rpc("setLogLevel") do (level: string) -> bool:
|
||||||
|
{.gcsafe.}: # It's probably not, actually. Hopefully we don't log from threads...
|
||||||
|
updateLogLevel(level)
|
||||||
|
return true
|
||||||
|
@ -30,8 +30,8 @@ const
|
|||||||
|
|
||||||
defaultEth2TcpPort* = 9000
|
defaultEth2TcpPort* = 9000
|
||||||
|
|
||||||
# This is not part of the spec yet!
|
# This is not part of the spec yet! Keep in sync with BASE_RPC_PORT
|
||||||
defaultEth2RpcPort* = 9090
|
defaultEth2RpcPort* = 9190
|
||||||
|
|
||||||
func getBeaconBlocksTopic*(forkDigest: ForkDigest): string =
|
func getBeaconBlocksTopic*(forkDigest: ForkDigest): string =
|
||||||
try:
|
try:
|
||||||
|
@ -173,3 +173,13 @@ Show a list of peers that the beacon node is connected to.
|
|||||||
```
|
```
|
||||||
curl -d '{"jsonrpc":"2.0","id":"id","method":"peers","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq
|
curl -d '{"jsonrpc":"2.0","id":"id","method":"peers","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Nimbus extensions
|
||||||
|
|
||||||
|
### setLogLevel
|
||||||
|
|
||||||
|
Set the current logging level dynamically: TRACE, DEBUG, INFO, NOTICE, WARN, ERROR or FATAL
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -d '{"jsonrpc":"2.0","id":"id","method":"setLogLevel","params":["DEBUG; TRACE:discv5,libp2p; REQUIRED:none; DISABLED:none"] }' -H 'Content-Type: application/json' localhost:9190 -s | jq
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user