mirror of https://github.com/waku-org/nwaku.git
chore: libwaku - allow to properly set the log level in libwaku and unify a little (#2708)
* waku.nimble: set properly chronicles compilation flags for static libwaku * adapt examples to new log setup
This commit is contained in:
parent
e7b0777d25
commit
3faffdbcaa
|
@ -4,7 +4,7 @@ else:
|
|||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, strutils, os, sequtils, net],
|
||||
std/[options, strutils, sequtils, net],
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
|
@ -43,16 +43,8 @@ when isMainModule:
|
|||
error "failure while loading the configuration", error = error
|
||||
quit(QuitFailure)
|
||||
|
||||
## Logging setup
|
||||
# Adhere to NO_COLOR initiative: https://no-color.org/
|
||||
let color =
|
||||
try:
|
||||
not parseBool(os.getEnv("NO_COLOR", "false"))
|
||||
except CatchableError:
|
||||
true
|
||||
|
||||
logging.setupLogLevel(conf.logLevel)
|
||||
logging.setupLogFormat(conf.logFormat, color)
|
||||
## Also called within Waku.init. The call to startRestServerEsentials needs the following line
|
||||
logging.setupLog(conf.logLevel, conf.logFormat)
|
||||
|
||||
case conf.cmd
|
||||
of generateRlnKeystore:
|
||||
|
|
|
@ -276,7 +276,8 @@ int main(int argc, char** argv) {
|
|||
\"store\": %s, \
|
||||
\"storeMessageDbUrl\": \"%s\", \
|
||||
\"storeMessageRetentionPolicy\": \"%s\", \
|
||||
\"storeMaxNumDbConnections\": %d \
|
||||
\"storeMaxNumDbConnections\": %d , \
|
||||
\"logLevel\": \"DEBUG\" \
|
||||
}", cfgNode.host,
|
||||
cfgNode.port,
|
||||
cfgNode.key,
|
||||
|
|
|
@ -219,6 +219,7 @@ int main(int argc, char** argv) {
|
|||
\"port\": %d, \
|
||||
\"key\": \"%s\", \
|
||||
\"relay\": %s, \
|
||||
\"logLevel\": \"DEBUG\" \
|
||||
}", cfgNode.host,
|
||||
cfgNode.port,
|
||||
cfgNode.key,
|
||||
|
|
|
@ -69,7 +69,7 @@ proc maintainSubscription(
|
|||
proc setupAndSubscribe(rng: ref HmacDrbgContext) =
|
||||
let filterPeer = parsePeerInfo(FilterPeer).get()
|
||||
|
||||
setupLogLevel(logging.LogLevel.NOTICE)
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
notice "starting filter subscriber"
|
||||
|
||||
var
|
||||
|
|
|
@ -193,6 +193,7 @@ type WakuConfig struct {
|
|||
Port int `json:"port,omitempty"`
|
||||
NodeKey string `json:"key,omitempty"`
|
||||
EnableRelay bool `json:"relay"`
|
||||
LogLevel string `json:"logLevel"`
|
||||
}
|
||||
|
||||
type WakuNode struct {
|
||||
|
@ -447,6 +448,7 @@ func main() {
|
|||
Port: 30304,
|
||||
NodeKey: "11d0dcea28e86f81937a3bd1163473c7fbc0a0db54fd72914849bc47bdf78710",
|
||||
EnableRelay: true,
|
||||
LogLevel: "DEBUG",
|
||||
}
|
||||
|
||||
node, err := WakuNew(config)
|
||||
|
|
|
@ -42,7 +42,7 @@ proc publishMessages(
|
|||
proc setupAndPublish(rng: ref HmacDrbgContext) =
|
||||
let lightpushPeer = parsePeerInfo(LightpushPeer).get()
|
||||
|
||||
setupLogLevel(logging.LogLevel.NOTICE)
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
notice "starting lightpush publisher"
|
||||
|
||||
var
|
||||
|
|
|
@ -21,6 +21,7 @@ var cfg = `{
|
|||
"port": 60001,
|
||||
"key": "364d111d729a6eb6d3e6113e163f017b5ef03a6f94c9b5b7bb1bb36fa5cb07a9",
|
||||
"relay": true
|
||||
"logLevel": "DEBUG"
|
||||
}`
|
||||
|
||||
function event_handler(event) {
|
||||
|
|
|
@ -38,7 +38,8 @@ const discv5Port = 9000
|
|||
|
||||
proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLogLevel(logging.LogLevel.NOTICE)
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
notice "starting publisher", wakuPort = wakuPort, discv5Port = discv5Port
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
||||
|
|
|
@ -49,7 +49,8 @@ json_config = "{ \
|
|||
\"host\": \"%s\", \
|
||||
\"port\": %d, \
|
||||
\"key\": \"%s\", \
|
||||
\"relay\": %s \
|
||||
\"relay\": %s ,\
|
||||
\"logLevel\": \"DEBUG\" \
|
||||
}" % (args.host,
|
||||
int(args.port),
|
||||
args.key,
|
||||
|
|
|
@ -63,7 +63,8 @@ fn main() {
|
|||
\"host\": \"127.0.0.1\",\
|
||||
\"port\": 60000, \
|
||||
\"key\": \"0d714a1fada214dead6dc9c7274581ec20ff292451866e7d6d677dc818e8ccd2\", \
|
||||
\"relay\": true \
|
||||
\"relay\": true ,\
|
||||
\"logLevel\": \"DEBUG\"
|
||||
}";
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -36,7 +36,8 @@ const discv5Port = 8000
|
|||
|
||||
proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLogLevel(logging.LogLevel.NOTICE)
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
notice "starting subscriber", wakuPort = wakuPort, discv5Port = discv5Port
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
|
|
|
@ -11,16 +11,7 @@ logScope:
|
|||
|
||||
when isMainModule:
|
||||
## Logging setup
|
||||
|
||||
# Adhere to NO_COLOR initiative: https://no-color.org/
|
||||
let color =
|
||||
try:
|
||||
not parseBool(os.getEnv("NO_COLOR", "false"))
|
||||
except CatchableError:
|
||||
true
|
||||
|
||||
logging.setupLogLevel(logging.LogLevel.INFO)
|
||||
logging.setupLogFormat(logging.LogFormat.TEXT, color)
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
info "Starting Waku Stealth Commitment Protocol"
|
||||
info "Starting Waku Node"
|
||||
|
|
10
waku.nimble
10
waku.nimble
|
@ -105,8 +105,14 @@ task chat2bridge, "Build chat2bridge":
|
|||
### C Bindings
|
||||
task libwakuStatic, "Build the cbindings waku node library":
|
||||
let name = "libwaku"
|
||||
buildLibrary name, "library/", "-d:chronicles_log_level=ERROR", "static"
|
||||
buildLibrary name,
|
||||
"library/",
|
||||
"""-d:chronicles_line_numbers -d:chronicles_runtime_filtering=on -d:chronicles_sinks="textlines,json" -d:chronicles_default_output_device=Dynamic -d:chronicles_disabled_topics="eth,dnsdisc.client" """,
|
||||
"static"
|
||||
|
||||
task libwakuDynamic, "Build the cbindings waku node library":
|
||||
let name = "libwaku"
|
||||
buildLibrary name, "library/", "-d:chronicles_log_level=ERROR", "dynamic"
|
||||
buildLibrary name,
|
||||
"library/",
|
||||
"""-d:chronicles_line_numbers -d:chronicles_runtime_filtering=on -d:chronicles_sinks="textlines,json" -d:chronicles_default_output_device=Dynamic -d:chronicles_disabled_topics="eth,dnsdisc.client" """,
|
||||
"dynamic"
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
## This code has been copied and addapted from `status-im/nimbu-eth2` project.
|
||||
## Link: https://github.com/status-im/nimbus-eth2/blob/c585b0a5b1ae4d55af38ad7f4715ad455e791552/beacon_chain/nimbus_binary_common.nim
|
||||
import std/typetraits, chronicles, chronicles/log_output, chronicles/topics_registry
|
||||
import
|
||||
std/[typetraits, os, strutils],
|
||||
chronicles,
|
||||
chronicles/log_output,
|
||||
chronicles/topics_registry
|
||||
|
||||
export chronicles.LogLevel
|
||||
|
||||
|
@ -61,11 +65,11 @@ proc writeAndFlush(f: File, s: LogOutputStr) =
|
|||
|
||||
## Setup
|
||||
|
||||
proc setupLogLevel*(level: LogLevel) =
|
||||
proc setupLogLevel(level: LogLevel) =
|
||||
# TODO: Support per topic level configuratio
|
||||
topics_registry.setLogLevel(level)
|
||||
|
||||
proc setupLogFormat*(format: LogFormat, color = true) =
|
||||
proc setupLogFormat(format: LogFormat, color = true) =
|
||||
proc noOutputWriter(logLevel: LogLevel, msg: LogOutputStr) =
|
||||
discard
|
||||
|
||||
|
@ -90,3 +94,15 @@ proc setupLogFormat*(format: LogFormat, color = true) =
|
|||
"the present module should be compiled with '-d:chronicles_default_output_device=dynamic' " &
|
||||
"and '-d:chronicles_sinks=\"textlines,json\"' options"
|
||||
.}
|
||||
|
||||
proc setupLog*(level: LogLevel, format: LogFormat) =
|
||||
## Logging setup
|
||||
# Adhere to NO_COLOR initiative: https://no-color.org/
|
||||
let color =
|
||||
try:
|
||||
not parseBool(os.getEnv("NO_COLOR", "false"))
|
||||
except CatchableError:
|
||||
true
|
||||
|
||||
setupLogLevel(level)
|
||||
setupLogFormat(format, color)
|
||||
|
|
|
@ -92,7 +92,7 @@ proc init*(T: type Waku, conf: WakuNodeConf): Result[Waku, string] =
|
|||
var confCopy = conf
|
||||
let rng = crypto.newRng()
|
||||
|
||||
logging.setupLogLevel(confCopy.logLevel)
|
||||
logging.setupLog(conf.logLevel, conf.logFormat)
|
||||
|
||||
case confCopy.clusterId
|
||||
|
||||
|
|
Loading…
Reference in New Issue