Skip to content

Commit

Permalink
feat: improve logging (#235)
Browse files Browse the repository at this point in the history
* feat: improve logging

* fix: add missing header

* fix: replace `init_logging` with `try_init_log_from_env`

`init_logging` code is kept unused waiting for
eclipse-zenoh/zenoh#1165
  • Loading branch information
wyfo authored Jun 18, 2024
1 parent c3ce7ef commit 664e9c9
Show file tree
Hide file tree
Showing 20 changed files with 393 additions and 72 deletions.
235 changes: 208 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/z_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 2 additions & 8 deletions examples/z_pub_thr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_queryable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_scout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/z_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_sub_queued.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/z_sub_thr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 664e9c9

Please sign in to comment.