Added support for missing logLevel/logFormat in new API create_node

This commit is contained in:
NagyZoltanPeter 2026-02-13 14:07:01 +01:00
parent 124f332284
commit 12d3471355
No known key found for this signature in database
GPG Key ID: 3E1F97CF4A7B6F42
3 changed files with 36 additions and 3 deletions

View File

@ -1,4 +1,4 @@
#include "../logosdelivery.h"
#include "../liblogosdelivery.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@ -104,7 +104,7 @@ int main() {
// Configuration JSON for creating a node
const char *config = "{"
"\"logLevel\": \"TRACE\","
"\"logLevel\": \"DEBUG\","
// "\"mode\": \"Edge\","
"\"mode\": \"Core\","
"\"clusterId\": 42,"

View File

@ -1,9 +1,10 @@
import std/[json, options]
import std/[json, options, strutils]
import chronos, results, ffi
import
waku/factory/waku,
waku/node/waku_node,
waku/api/[api, api_conf, types],
waku/common/logging,
waku/events/message_events,
../declare_lib,
../json_event
@ -64,11 +65,32 @@ registerReqFFI(CreateNodeRequest, ctx: ptr FFIContext[Waku]):
clusterId = clusterId,
)
# Parse log configuration
let logLevel =
if jsonNode.hasKey("logLevel"):
try:
parseEnum[logging.LogLevel](jsonNode["logLevel"].getStr().toUpperAscii())
except ValueError:
logging.LogLevel.INFO # Default if parsing fails
else:
logging.LogLevel.INFO
let logFormat =
if jsonNode.hasKey("logFormat"):
try:
parseEnum[logging.LogFormat](jsonNode["logFormat"].getStr().toUpperAscii())
except ValueError:
logging.LogFormat.TEXT # Default if parsing fails
else:
logging.LogFormat.TEXT
# Build node config
let nodeConfig = NodeConfig.init(
mode = mode,
protocolsConfig = protocolsConfig,
networkingConfig = networkingConfig,
logLevel = logLevel,
logFormat = logFormat,
)
# Create the node

View File

@ -4,6 +4,7 @@ import results
import
waku/common/utils/parse_size_units,
waku/common/logging,
waku/factory/waku_conf,
waku/factory/conf_builder/conf_builder,
waku/factory/networks_config,
@ -87,6 +88,8 @@ type NodeConfig* {.requiresInit.} = object
networkingConfig: NetworkingConfig
ethRpcEndpoints: seq[string]
p2pReliability: bool
logLevel: LogLevel
logFormat: LogFormat
proc init*(
T: typedesc[NodeConfig],
@ -95,6 +98,8 @@ proc init*(
networkingConfig: NetworkingConfig = DefaultNetworkingConfig,
ethRpcEndpoints: seq[string] = @[],
p2pReliability: bool = false,
logLevel: LogLevel = LogLevel.INFO,
logFormat: LogFormat = LogFormat.TEXT,
): T =
return T(
mode: mode,
@ -102,11 +107,17 @@ proc init*(
networkingConfig: networkingConfig,
ethRpcEndpoints: ethRpcEndpoints,
p2pReliability: p2pReliability,
logLevel: logLevel,
logFormat: logFormat,
)
proc toWakuConf*(nodeConfig: NodeConfig): Result[WakuConf, string] =
var b = WakuConfBuilder.init()
# Apply log configuration
b.withLogLevel(nodeConfig.logLevel)
b.withLogFormat(nodeConfig.logFormat)
# Apply networking configuration
let networkingConfig = nodeConfig.networkingConfig
let ip = parseIpAddress(networkingConfig.listenIpv4)