topic specific log level config

This commit is contained in:
Prem Chaitanya Prathi 2025-10-03 15:21:16 +05:30
parent c581ce7ef0
commit e6e28c7838
No known key found for this signature in database
9 changed files with 64 additions and 7 deletions

View File

@ -222,7 +222,7 @@ testwaku: | build deps rln-deps librln
wakunode2: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
\
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) -d:chronicles_runtime_filtering:on waku.nims
benchmarks: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \

View File

@ -96,7 +96,7 @@ when isMainModule:
quit(QuitFailure)
c_signal(ansi_c.SIGSEGV, handleSigsegv)
logging.setTopicConfig(wakuNodeConf.logTopicsConfig)
info "Node setup complete"
runForever()

View File

@ -24,4 +24,5 @@ rendezvous = true
listen-address = "127.0.0.1"
nat = "extip:127.0.0.1"
ip-colocation-limit=0
log-topic-config=["wakumix:TRACE"]
#staticnode = ["/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o", "/ip4/127.0.0.1/tcp/60003/p2p/16Uiu2HAmTEDHwAziWUSz6ZE23h5vxG2o4Nn7GazhMor4bVuMXTrA","/ip4/127.0.0.1/tcp/60004/p2p/16Uiu2HAmPwRKZajXtfb1Qsv45VVfRZgK3ENdfmnqzSrVm3BczF6f","/ip4/127.0.0.1/tcp/60005/p2p/16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu"]

View File

@ -1,5 +1,5 @@
import
std/[strutils, strformat, sequtils],
std/[strutils, strformat, sequtils, enumutils],
results,
chronicles,
chronos,
@ -71,6 +71,13 @@ type WakuNodeConf* = object
name: "log-format"
.}: logging.LogFormat
logTopicsConfig* {.
desc:
"Sets the log level for specific topics. Format: <topic>:<level>. Argument may be repeated. ",
defaultValue: newSeq[LogTopicConfig](0),
name: "log-topic-config"
.}: seq[LogTopicConfig]
rlnRelayCredPath* {.
desc: "The path for persisting rln-relay credential",
defaultValue: "",
@ -703,6 +710,21 @@ proc isNumber(x: string): bool =
except ValueError:
result = false
proc parseCmdArg*(T: type LogTopicConfig, p: string): T =
let elements = p.split(":")
if elements.len != 2:
raise newException(
ValueError, "Invalid format for logTopicsConfig expected topic:loglevel"
)
var logTopicConfig: LogTopicConfig
try:
let logLevel = parseEnum[LogLevel](elements[1])
logTopicConfig = LogTopicConfig(topic: elements[0], level: logLevel)
except ValueError:
raise newException(ValueError, "Invalid log level")
return logTopicConfig
proc parseCmdArg*(T: type MixNodePubInfo, p: string): T =
let elements = p.split(":")
if elements.len != 2:
@ -803,6 +825,22 @@ proc readValue*(
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())
proc readValue*(
r: var TomlReader, value: var LogTopicConfig
) {.raises: [SerializationError].} =
try:
value = parseCmdArg(LogTopicConfig, r.readValue(string))
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())
proc readValue*(
r: var EnvvarReader, value: var LogTopicConfig
) {.raises: [SerializationError].} =
try:
value = parseCmdArg(LogTopicConfig, r.readValue(string))
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())
proc readValue*(
r: var TomlReader, value: var MixNodePubInfo
) {.raises: [SerializationError].} =
@ -911,6 +949,7 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] =
b.withLogLevel(n.logLevel)
b.withLogFormat(n.logFormat)
b.withLogTopicsConfig(n.logTopicsConfig)
b.rlnRelayConf.withEnabled(n.rlnRelay)
if n.rlnRelayCredPath != "":

View File

@ -14,6 +14,10 @@ type LogFormat* = enum
TEXT
JSON
type LogTopicConfig* = object
topic*: string
level*: LogLevel
## Utils
proc stripAnsi(v: string): string =
@ -63,7 +67,6 @@ proc writeAndFlush(f: syncio.File, s: LogOutputStr) =
## Setup
proc setupLogLevel(level: LogLevel) =
# TODO: Support per topic level configuratio
topics_registry.setLogLevel(level)
proc setupLogFormat(format: LogFormat, color = true) =
@ -103,3 +106,11 @@ proc setupLog*(level: LogLevel, format: LogFormat) =
setupLogLevel(level)
setupLogFormat(format, color)
proc setTopicConfig*(logTopicsConfig: seq[LogTopicConfig]) =
for topicConf in logTopicsConfig:
if not topics_registry.setTopicState(topicConf.topic, Enabled, topicConf.level):
error "Unknown logging topic or unable to set loglevel",
topic = topicConf.topic, level = $topicConf.level
{.pop.}

View File

@ -102,6 +102,7 @@ type WakuConfBuilder* = object
logLevel: Option[logging.LogLevel]
logFormat: Option[logging.LogFormat]
logTopicsConfig: seq[LogTopicConfig]
natStrategy: Option[string]
@ -221,6 +222,11 @@ proc withLogLevel*(b: var WakuConfBuilder, logLevel: logging.LogLevel) =
proc withLogFormat*(b: var WakuConfBuilder, logFormat: logging.LogFormat) =
b.logFormat = some(logFormat)
proc withLogTopicsConfig*(
b: var WakuConfBuilder, logTopicsConfig: seq[LogTopicConfig]
) =
b.logTopicsConfig = logTopicsConfig
proc withP2pTcpPort*(b: var WakuConfBuilder, p2pTcpPort: Port) =
b.p2pTcpPort = some(p2pTcpPort)
@ -645,6 +651,7 @@ proc build*(
maxMessageSizeBytes: maxMessageSizeBytes,
logLevel: logLevel,
logFormat: logFormat,
logTopicsConfig: builder.logTopicsConfig,
# TODO: Separate builders
endpointConf: EndpointConf(
natStrategy: natStrategy,

View File

@ -164,8 +164,6 @@ proc new*(
): Future[Result[Waku, string]] {.async.} =
let rng = crypto.newRng()
logging.setupLog(wakuConf.logLevel, wakuConf.logFormat)
?wakuConf.validate()
wakuConf.logConf()

View File

@ -126,6 +126,7 @@ type WakuConf* {.requiresInit.} = ref object
logLevel*: logging.LogLevel
logFormat*: logging.LogFormat
logTopicsConfig*: seq[LogTopicConfig]
peerPersistence*: bool
# TODO: should clearly be a uint

View File

@ -19,7 +19,7 @@ import
../common/nimchronos
logScope:
topics = "waku mix"
topics = "wakumix"
const mixMixPoolSize = 3