mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-03-06 17:13:35 +00:00
Added support for missing logLevel/logFormat in new API create_node
This commit is contained in:
parent
124f332284
commit
12d3471355
@ -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,"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user