|
1 | 1 | import |
2 | | - std/[strutils, strformat, sequtils], |
| 2 | + std/[strutils, strformat, sequtils, enumutils], |
3 | 3 | results, |
4 | 4 | chronicles, |
5 | 5 | chronos, |
@@ -71,6 +71,13 @@ type WakuNodeConf* = object |
71 | 71 | name: "log-format" |
72 | 72 | .}: logging.LogFormat |
73 | 73 |
|
| 74 | + logTopicsConfig* {. |
| 75 | + desc: |
| 76 | + "Sets the log level for specific topics. Format: <topic>:<level>. Argument may be repeated. ", |
| 77 | + defaultValue: newSeq[LogTopicConfig](0), |
| 78 | + name: "log-topic-config" |
| 79 | + .}: seq[LogTopicConfig] |
| 80 | + |
74 | 81 | rlnRelayCredPath* {. |
75 | 82 | desc: "The path for persisting rln-relay credential", |
76 | 83 | defaultValue: "", |
@@ -703,6 +710,21 @@ proc isNumber(x: string): bool = |
703 | 710 | except ValueError: |
704 | 711 | result = false |
705 | 712 |
|
| 713 | +proc parseCmdArg*(T: type LogTopicConfig, p: string): T = |
| 714 | + let elements = p.split(":") |
| 715 | + if elements.len != 2: |
| 716 | + raise newException( |
| 717 | + ValueError, "Invalid format for logTopicsConfig expected topic:loglevel" |
| 718 | + ) |
| 719 | + |
| 720 | + var logTopicConfig: LogTopicConfig |
| 721 | + try: |
| 722 | + let logLevel = parseEnum[LogLevel](elements[1]) |
| 723 | + logTopicConfig = LogTopicConfig(topic: elements[0], level: logLevel) |
| 724 | + except ValueError: |
| 725 | + raise newException(ValueError, "Invalid log level") |
| 726 | + return logTopicConfig |
| 727 | + |
706 | 728 | proc parseCmdArg*(T: type MixNodePubInfo, p: string): T = |
707 | 729 | let elements = p.split(":") |
708 | 730 | if elements.len != 2: |
@@ -803,6 +825,22 @@ proc readValue*( |
803 | 825 | except CatchableError: |
804 | 826 | raise newException(SerializationError, getCurrentExceptionMsg()) |
805 | 827 |
|
| 828 | +proc readValue*( |
| 829 | + r: var TomlReader, value: var LogTopicConfig |
| 830 | +) {.raises: [SerializationError].} = |
| 831 | + try: |
| 832 | + value = parseCmdArg(LogTopicConfig, r.readValue(string)) |
| 833 | + except CatchableError: |
| 834 | + raise newException(SerializationError, getCurrentExceptionMsg()) |
| 835 | + |
| 836 | +proc readValue*( |
| 837 | + r: var EnvvarReader, value: var LogTopicConfig |
| 838 | +) {.raises: [SerializationError].} = |
| 839 | + try: |
| 840 | + value = parseCmdArg(LogTopicConfig, r.readValue(string)) |
| 841 | + except CatchableError: |
| 842 | + raise newException(SerializationError, getCurrentExceptionMsg()) |
| 843 | + |
806 | 844 | proc readValue*( |
807 | 845 | r: var TomlReader, value: var MixNodePubInfo |
808 | 846 | ) {.raises: [SerializationError].} = |
@@ -911,6 +949,7 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = |
911 | 949 |
|
912 | 950 | b.withLogLevel(n.logLevel) |
913 | 951 | b.withLogFormat(n.logFormat) |
| 952 | + b.withLogTopicsConfig(n.logTopicsConfig) |
914 | 953 |
|
915 | 954 | b.rlnRelayConf.withEnabled(n.rlnRelay) |
916 | 955 | if n.rlnRelayCredPath != "": |
|
0 commit comments