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
|
||||
logLevel* {.
|
||||
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
|
||||
|
||||
logFile* {.
|
||||
|
@ -28,6 +28,19 @@ proc setupStdoutLogging*(logLevel: string) =
|
||||
except IOError as 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]) =
|
||||
randomize()
|
||||
|
||||
@ -49,16 +62,7 @@ proc setupLogging*(logLevel: string, logFile: Option[OutFile]) =
|
||||
warn "The --log-file option is not active in the current build"
|
||||
|
||||
try:
|
||||
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
|
||||
updateLogLevel(logLevel)
|
||||
except ValueError as err:
|
||||
stderr.write "Invalid value for --log-level. " & err.msg
|
||||
quit 1
|
||||
|
@ -10,7 +10,7 @@ import
|
||||
stew/byteutils,
|
||||
json_rpc/[rpcserver, jsonmarshal],
|
||||
|
||||
../beacon_node_common, ../eth2_network,
|
||||
../beacon_node_common, ../nimbus_binary_common, ../eth2_network,
|
||||
../spec/[digest, datatypes, presets]
|
||||
|
||||
logScope: topics = "nimbusapi"
|
||||
@ -83,3 +83,8 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
||||
res.add("peers", peers)
|
||||
|
||||
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
|
||||
|
||||
# This is not part of the spec yet!
|
||||
defaultEth2RpcPort* = 9090
|
||||
# This is not part of the spec yet! Keep in sync with BASE_RPC_PORT
|
||||
defaultEth2RpcPort* = 9190
|
||||
|
||||
func getBeaconBlocksTopic*(forkDigest: ForkDigest): string =
|
||||
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
|
||||
```
|
||||
|
||||
## 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