diff --git a/Cargo.lock b/Cargo.lock index 6858c61e..59175b1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,6 +116,45 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc" +[[package]] +name = "asn1-rs" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ad1373757efa0f70ec53939aabc7152e1591cb485208052993070ac8d2429d" +dependencies = [ + "asn1-rs-derive", + "asn1-rs-impl", + "displaydoc", + "nom", + "num-traits", + "rusticata-macros", + "thiserror", + "time", +] + +[[package]] +name = "asn1-rs-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", + "synstructure", +] + +[[package]] +name = "asn1-rs-impl" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + [[package]] name = "async-channel" version = "1.9.0" @@ -538,6 +577,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "der-parser" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cd0a5c643689626bec213c4d8bd4d96acc8ffdb4ad4bb6bc16abf27d5f4b553" +dependencies = [ + "asn1-rs", + "displaydoc", + "nom", + "num-bigint", + "num-traits", + "rusticata-macros", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "digest" version = "0.10.7" @@ -571,6 +633,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "displaydoc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + [[package]] name = "dyn-clone" version = "1.0.17" @@ -1207,6 +1280,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -1253,6 +1332,16 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1291,6 +1380,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -1340,6 +1435,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "oid-registry" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c958dd45046245b9c3c2547369bb634eb461670b2e7e0de552905801a648d1d" +dependencies = [ + "asn1-rs", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -1633,6 +1737,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1955,6 +2065,15 @@ dependencies = [ "semver", ] +[[package]] +name = "rusticata-macros" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632" +dependencies = [ + "nom", +] + [[package]] name = "rustix" version = "0.37.27" @@ -2432,6 +2551,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + [[package]] name = "target-lexicon" version = "0.12.14" @@ -2468,6 +2598,37 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -3097,21 +3258,38 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +[[package]] +name = "x509-parser" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcbc162f30700d6f3f82a24bf7cc62ffe7caea42c0b2cba8bf7f3ae50cf51f69" +dependencies = [ + "asn1-rs", + "data-encoding", + "der-parser", + "lazy_static", + "nom", + "oid-registry", + "rusticata-macros", + "thiserror", + "time", +] + [[package]] name = "zenoh" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "ahash", "async-trait", "base64 0.21.7", - "const_format", "event-listener 4.0.3", "flume", "form_urlencoded", "futures", "git-version", "lazy_static", + "once_cell", "ordered-float", "paste", "petgraph", @@ -3155,7 +3333,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "zenoh-collections", ] @@ -3163,7 +3341,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "serde", "tracing", @@ -3175,12 +3353,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" [[package]] name = "zenoh-config" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "flume", "json5", @@ -3193,6 +3371,7 @@ dependencies = [ "uhlc", "validated_struct", "zenoh-core", + "zenoh-macros", "zenoh-protocol", "zenoh-result", "zenoh-util", @@ -3201,7 +3380,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-global-executor", "lazy_static", @@ -3213,7 +3392,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "aes", "hmac", @@ -3226,7 +3405,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "hashbrown 0.14.3", "keyed-set", @@ -3240,7 +3419,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "zenoh-config", @@ -3258,7 +3437,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "flume", @@ -3282,7 +3461,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "base64 0.21.7", @@ -3299,6 +3478,7 @@ dependencies = [ "tokio-util", "tracing", "webpki-roots", + "x509-parser", "zenoh-collections", "zenoh-config", "zenoh-core", @@ -3313,7 +3493,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "tokio", @@ -3331,7 +3511,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "base64 0.21.7", @@ -3346,6 +3526,7 @@ dependencies = [ "tokio-util", "tracing", "webpki-roots", + "x509-parser", "zenoh-collections", "zenoh-config", "zenoh-core", @@ -3360,7 +3541,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "socket2 0.5.6", @@ -3381,7 +3562,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "futures", @@ -3401,7 +3582,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "futures-util", @@ -3422,7 +3603,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "proc-macro2", "quote", @@ -3433,9 +3614,8 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ - "const_format", "libloading", "serde", "serde_json", @@ -3449,7 +3629,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "const_format", "rand", @@ -3480,7 +3660,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "anyhow", ] @@ -3488,7 +3668,7 @@ dependencies = [ [[package]] name = "zenoh-runtime" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "futures", "lazy_static", @@ -3503,7 +3683,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "event-listener 4.0.3", "futures", @@ -3517,7 +3697,7 @@ dependencies = [ [[package]] name = "zenoh-task" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "futures", "tokio", @@ -3530,7 +3710,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-trait", "flume", @@ -3562,10 +3742,11 @@ dependencies = [ [[package]] name = "zenoh-util" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#b9f65063ea397d0e847ce96f262dccce4b406d55" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#86490c17e2ad8977b14e98b33f7b42482f75c433" dependencies = [ "async-std", "async-trait", + "const_format", "flume", "home", "humantime", diff --git a/examples/z_delete.py b/examples/z_delete.py index 98ba0fd1..8db06c8e 100644 --- a/examples/z_delete.py +++ b/examples/z_delete.py @@ -78,7 +78,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_get.py b/examples/z_get.py index 7ff91d70..a417b594 100644 --- a/examples/z_get.py +++ b/examples/z_get.py @@ -99,7 +99,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_info.py b/examples/z_info.py index 94c090db..dc84eeff 100644 --- a/examples/z_info.py +++ b/examples/z_info.py @@ -69,7 +69,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_ping.py b/examples/z_ping.py index 39000478..00728a33 100644 --- a/examples/z_ping.py +++ b/examples/z_ping.py @@ -94,7 +94,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_pong.py b/examples/z_pong.py index b5d34958..e00e7d3d 100644 --- a/examples/z_pong.py +++ b/examples/z_pong.py @@ -78,7 +78,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_pub.py b/examples/z_pub.py index 51890894..97475d8a 100644 --- a/examples/z_pub.py +++ b/examples/z_pub.py @@ -96,7 +96,7 @@ def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_pub_thr.py b/examples/z_pub_thr.py index 2de08e98..9ee1ac67 100644 --- a/examples/z_pub_thr.py +++ b/examples/z_pub_thr.py @@ -75,7 +75,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() data = bytearray() for i in range(0, size): @@ -89,13 +89,7 @@ def main(): print("Press CTRL-C to quit...") while True: - try: - pub.put(bytes(data)) - except BaseException: - print("Ctrl+C") - pub.undeclare() - print("Ctrl+C") - raise + pub.put(bytes(data)) if __name__ == "__main__": diff --git a/examples/z_pull.py b/examples/z_pull.py index 14278a6c..7f6f03f1 100644 --- a/examples/z_pull.py +++ b/examples/z_pull.py @@ -90,7 +90,7 @@ def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_put.py b/examples/z_put.py index c93f264f..87ce72df 100644 --- a/examples/z_put.py +++ b/examples/z_put.py @@ -87,7 +87,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_queryable.py b/examples/z_queryable.py index f9c6617e..bfbd8195 100644 --- a/examples/z_queryable.py +++ b/examples/z_queryable.py @@ -111,7 +111,7 @@ def queryable_callback(query): def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_scout.py b/examples/z_scout.py index 0cae3118..0cae2fa4 100644 --- a/examples/z_scout.py +++ b/examples/z_scout.py @@ -18,7 +18,7 @@ def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Scouting...") scout = zenoh.scout(what="peer|router") diff --git a/examples/z_storage.py b/examples/z_storage.py index 3f76311f..3354e7ef 100644 --- a/examples/z_storage.py +++ b/examples/z_storage.py @@ -117,7 +117,7 @@ def query_handler(query: zenoh.Query): def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_sub.py b/examples/z_sub.py index baf08093..82179da4 100644 --- a/examples/z_sub.py +++ b/examples/z_sub.py @@ -79,7 +79,7 @@ # Zenoh code --- --- --- --- --- --- --- --- --- --- --- def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_sub_queued.py b/examples/z_sub_queued.py index 897cdd49..6d680d12 100644 --- a/examples/z_sub_queued.py +++ b/examples/z_sub_queued.py @@ -81,7 +81,7 @@ def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() print("Opening session...") with zenoh.open(conf) as session: diff --git a/examples/z_sub_thr.py b/examples/z_sub_thr.py index dc6be158..8dad03a2 100644 --- a/examples/z_sub_thr.py +++ b/examples/z_sub_thr.py @@ -113,7 +113,7 @@ def report(): def main(): # initiate logging - zenoh.init_logging() + zenoh.try_init_log_from_env() with zenoh.open(conf) as session: session.declare_subscriber( diff --git a/src/lib.rs b/src/lib.rs index 0d001ef9..bd70d520 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,8 @@ mod encoding; mod handlers; mod info; mod key_expr; -mod logging; +#[allow(unused)] +mod logging; // https://github.com/eclipse-zenoh/zenoh-python/pull/235#discussion_r1644498390 mod macros; mod publisher; mod query; @@ -44,6 +45,11 @@ pub(crate) mod zenoh { use crate::handlers::{Callback, DefaultHandler, FifoChannel, Handler, RingChannel}; } + #[pyfunction] + fn try_init_log_from_env() { + zenoh::try_init_log_from_env(); + } + #[pymodule_export] use crate::{ bytes::{deserializer, serializer, ZBytes}, @@ -53,7 +59,6 @@ pub(crate) mod zenoh { info::SessionInfo, key_expr::KeyExpr, key_expr::SetIntersectionLevel, - logging::init_logging, publisher::{CongestionControl, Priority, Publisher}, query::{ConsolidationMode, Query, QueryTarget, Reply, ReplyError}, queryable::Queryable, diff --git a/src/logging.rs b/src/logging.rs index 0a653af5..6da5ee5f 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -1,6 +1,27 @@ -use std::thread; +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use std::{ + collections::HashMap, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + thread, +}; -use pyo3::{prelude::*, sync::GILOnceCell, types::PyDict}; +use pyo3::{exceptions::PyKeyError, prelude::*, sync::GILOnceCell, types::PyDict}; +use tracing::level_filters::LevelFilter; use zenoh_util::LogRecord; use crate::{macros::import, utils::MapInto}; @@ -17,7 +38,26 @@ pub(crate) fn init_logger(py: Python) -> PyResult<()> { Ok(()) } -fn handle_record(py: Python, record: LogRecord) -> PyResult<()> { +fn handle_record( + py: Python, + loggers: &mut HashMap, + record: LogRecord, +) -> PyResult<()> { + let mut logger_name = record.target.replace("::", "."); + if !logger_name.starts_with("zenoh") { + logger_name.insert_str(0, "zenoh.dependency."); + } + let logger = loggers + .entry(record.target.clone()) + .or_insert_with(|| { + import!(py, logging.getLogger) + .call1((&logger_name,)) + .map_or_else(|_| py.None(), Bound::unbind) + }) + .bind(py); + if logger.is_none() { + return Ok(()); + } let level = match record.level { tracing::Level::TRACE => 5, tracing::Level::DEBUG => 10, @@ -25,7 +65,6 @@ fn handle_record(py: Python, record: LogRecord) -> PyResult<()> { tracing::Level::WARN => 30, tracing::Level::ERROR => 40, }; - let logger = LOGGER.get(py).unwrap().bind(py); if !logger .call_method1("isEnabledFor", (level,)) .and_then(|obj| bool::extract_bound(&obj)) @@ -33,43 +72,146 @@ fn handle_record(py: Python, record: LogRecord) -> PyResult<()> { { return Ok(()); } - let factory = import!(py, logging.getLogRecordFactory).call0()?; - let kwargs = PyDict::new_bound(py); - for (k, v) in record.attributes { - kwargs.set_item(k, v)?; + let extra = PyDict::new_bound(py); + for (k, v) in &record.attributes { + extra.set_item(k, v)?; } - let record = factory.call( + extra.set_item("raw_attributes", extra.copy()?)?; + let formatted_attributes = record + .attributes + .iter() + .flat_map(|(k, v)| [k, "=", v]) + .collect::>() + .join("="); + extra.set_item("formatted_attributes", formatted_attributes)?; + let record = logger.call_method1( + "makeRecord", ( - LOGGER_NAME, + logger_name, level, record.file, record.line, record.message, py.None(), py.None(), + py.None(), + extra, ), - Some(&kwargs), )?; logger.call_method1("handle", (record,))?; Ok(()) } +#[derive(Clone)] +struct LogFilter(Arc); + +impl LogFilter { + // These constants normally matches `LevelFilter` internal representation + const TRACE: usize = 0; + const DEBUG: usize = 1; + const INFO: usize = 2; + const WARN: usize = 3; + const ERROR: usize = 4; + const OFF: usize = 5; + + fn new(py: Python) -> Self { + let this = Self(Arc::new(AtomicUsize::new(Self::OFF))); + this.reset(py); + this + } + + fn reset(&self, py: Python) { + let logger = LOGGER.get(py).unwrap().bind(py); + let level = logger + .call_method0("getEffectiveLevel") + .unwrap() + .extract::() + .unwrap(); + let filter = match level { + l if l <= 5 => Self::TRACE, + l if l <= 10 => Self::DEBUG, + l if l <= 20 => Self::INFO, + l if l <= 30 => Self::WARN, + l if l <= 40 => Self::ERROR, + _ => Self::OFF, + }; + self.0.store(filter, Ordering::Relaxed); + } + + fn filter(&self, level: tracing::Level) -> bool { + let filter = match self.0.load(Ordering::Relaxed) { + Self::TRACE => LevelFilter::TRACE, + Self::DEBUG => LevelFilter::DEBUG, + Self::INFO => LevelFilter::INFO, + Self::WARN => LevelFilter::WARN, + Self::ERROR => LevelFilter::ERROR, + Self::OFF => LevelFilter::OFF, + _ => unreachable!(), + }; + level <= filter + } +} + +#[pyclass] +struct LoggerCache { + inner: Py, + filter: LogFilter, +} + +#[pymethods] +impl LoggerCache { + fn __getitem__<'py>( + &self, + py: Python<'py>, + key: &Bound<'py, PyAny>, + ) -> PyResult> { + match self.inner.bind(py).get_item(key)? { + Some(value) => Ok(value), + None => Err(PyKeyError::new_err(key.clone().unbind())), + } + } + fn __setitem__(&self, py: Python, key: &Bound, value: &Bound) -> PyResult<()> { + self.inner.bind(py).set_item(key, value) + } + fn clear(&self, py: Python) { + self.inner.bind(py).clear(); + self.filter.reset(py); + tracing::callsite::rebuild_interest_cache(); + } +} + #[pyfunction] -#[pyo3(signature = (basic_config = true, **kwargs))] +#[pyo3(signature = (*, raw = false, basic_config = true, **kwargs))] pub(crate) fn init_logging( py: Python, + raw: bool, basic_config: bool, kwargs: Option<&Bound>, ) -> PyResult<()> { + if raw { + zenoh_util::try_init_log_from_env(); + return Ok(()); + } import!(py, logging.addLevelName).call1((5, "TRACE"))?; if basic_config { import!(py, logging.basicConfig).call((), kwargs)?; } + let filter = LogFilter::new(py); + let logger = LOGGER.get(py).unwrap().bind(py); + let cache = LoggerCache { + inner: PyDict::new_bound(py).unbind(), + filter: filter.clone(), + }; + logger.setattr("_cache", cache.into_py(py))?; let (tx, rx) = flume::unbounded(); - zenoh_util::init_log_with_callback(move |record| tx.send(record).unwrap()); + zenoh_util::init_log_with_callback( + move |meta| filter.filter(*meta.level()), + move |record| tx.send(record).unwrap(), + ); + let mut loggers = HashMap::new(); thread::spawn(move || { for record in rx { - Python::with_gil(|gil| handle_record(gil, record)).ok(); + Python::with_gil(|gil| handle_record(gil, &mut loggers, record)).ok(); } }); Ok(()) diff --git a/tests/test_session.py b/tests/test_session.py index 71c258db..40f9fa56 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -124,7 +124,7 @@ def sub_callback(sample: Sample): def test_session(): - zenoh.init_logging() + zenoh.try_init_log_from_env() (peer01, peer02) = open_session(["tcp/127.0.0.1:17447"]) run_session_qryrep(peer01, peer02) run_session_pubsub(peer01, peer02) diff --git a/zenoh/__init__.pyi b/zenoh/__init__.pyi index fd5711e5..a9f8ca77 100644 --- a/zenoh/__init__.pyi +++ b/zenoh/__init__.pyi @@ -18,7 +18,7 @@ from collections.abc import Callable, Iterable from datetime import datetime from enum import Enum, auto from pathlib import Path -from typing import Any, Generic, Never, Protocol, Self, TypeVar, final, overload +from typing import Any, Generic, Literal, Never, Self, TypeVar, final, overload from . import handlers as handlers from .handlers import Handler as Handler @@ -948,12 +948,11 @@ class ZenohId: def into_keyexpr(self) -> KeyExpr: ... def __str__(self) -> str: ... -def init_logging(basic_config: bool = True, **kwargs): - """Start redirecting all zenoh logs to Python logger named `zenoh`. +def try_init_log_from_env(): + """Redirect zenoh logs to stdout, according to the `RUST_LOG` environment variable. - If `basic_config=True`, which is the default, it also calls - `logging.basicConfig(**kwargs)` as a convenience. - """ + For example, `RUST_LOG=debug` will set the log level to DEBUG. + If `RUST_LOG` is not set, then logging is not enabled.""" def open(config: Config | None = None) -> Session: """Open a zenoh Session."""