diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index 34073e25d..474eef1f7 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -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: diff --git a/examples/cbindings/waku_example.c b/examples/cbindings/waku_example.c index 69e51687f..87e07977e 100644 --- a/examples/cbindings/waku_example.c +++ b/examples/cbindings/waku_example.c @@ -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, diff --git a/examples/cpp/waku.cpp b/examples/cpp/waku.cpp index ec8346520..cab7bacd8 100644 --- a/examples/cpp/waku.cpp +++ b/examples/cpp/waku.cpp @@ -219,6 +219,7 @@ int main(int argc, char** argv) { \"port\": %d, \ \"key\": \"%s\", \ \"relay\": %s, \ + \"logLevel\": \"DEBUG\" \ }", cfgNode.host, cfgNode.port, cfgNode.key, diff --git a/examples/filter_subscriber.nim b/examples/filter_subscriber.nim index bc6e587b1..9f850a879 100644 --- a/examples/filter_subscriber.nim +++ b/examples/filter_subscriber.nim @@ -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 diff --git a/examples/golang/waku.go b/examples/golang/waku.go index 587aa9f6e..22c8b7b0e 100644 --- a/examples/golang/waku.go +++ b/examples/golang/waku.go @@ -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) diff --git a/examples/lightpush_publisher.nim b/examples/lightpush_publisher.nim index 241c52bfc..8dee61fd1 100644 --- a/examples/lightpush_publisher.nim +++ b/examples/lightpush_publisher.nim @@ -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 diff --git a/examples/nodejs/waku.js b/examples/nodejs/waku.js index 87d01378c..258e34849 100644 --- a/examples/nodejs/waku.js +++ b/examples/nodejs/waku.js @@ -21,6 +21,7 @@ var cfg = `{ "port": 60001, "key": "364d111d729a6eb6d3e6113e163f017b5ef03a6f94c9b5b7bb1bb36fa5cb07a9", "relay": true + "logLevel": "DEBUG" }` function event_handler(event) { diff --git a/examples/publisher.nim b/examples/publisher.nim index 2a95c68e2..c266cda9f 100644 --- a/examples/publisher.nim +++ b/examples/publisher.nim @@ -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() diff --git a/examples/python/waku.py b/examples/python/waku.py index dbe0a573f..4d5f5643e 100644 --- a/examples/python/waku.py +++ b/examples/python/waku.py @@ -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, diff --git a/examples/rust/src/main.rs b/examples/rust/src/main.rs index 1580bfb4b..f5ff07c64 100644 --- a/examples/rust/src/main.rs +++ b/examples/rust/src/main.rs @@ -63,7 +63,8 @@ fn main() { \"host\": \"127.0.0.1\",\ \"port\": 60000, \ \"key\": \"0d714a1fada214dead6dc9c7274581ec20ff292451866e7d6d677dc818e8ccd2\", \ - \"relay\": true \ + \"relay\": true ,\ + \"logLevel\": \"DEBUG\" }"; unsafe { diff --git a/examples/subscriber.nim b/examples/subscriber.nim index 842a3a02d..45f06e1b9 100644 --- a/examples/subscriber.nim +++ b/examples/subscriber.nim @@ -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[])[] diff --git a/examples/wakustealthcommitments/wakustealthcommitments.nim b/examples/wakustealthcommitments/wakustealthcommitments.nim index 7d2655ed1..a6cf4a562 100644 --- a/examples/wakustealthcommitments/wakustealthcommitments.nim +++ b/examples/wakustealthcommitments/wakustealthcommitments.nim @@ -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" diff --git a/waku.nimble b/waku.nimble index f1169423f..1ca4f7913 100644 --- a/waku.nimble +++ b/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" diff --git a/waku/common/logging.nim b/waku/common/logging.nim index 7b242ba9c..a955d3d68 100644 --- a/waku/common/logging.nim +++ b/waku/common/logging.nim @@ -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) diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 9b8550886..a461f65c5 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -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