From 77edf63df533d5c96f846a71310efc0bcdbcd62b Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Fri, 13 Sep 2024 12:32:11 +0200 Subject: [PATCH] align logging with zenoh-c --- docs/commons.rst | 3 ++- include/zenoh/api/logging.hxx | 19 +++++++++++++++---- tests/zenohc/config.cxx | 2 +- zenoh-c | 2 +- zenoh-pico | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/commons.rst b/docs/commons.rst index f06d90f7..867896a2 100644 --- a/docs/commons.rst +++ b/docs/commons.rst @@ -79,4 +79,5 @@ Sample Logging ------- -.. doxygenfunction:: init_logging +.. doxygenfunction:: try_init_log_from_env +.. doxygenfunction:: init_log_from_env_or diff --git a/include/zenoh/api/logging.hxx b/include/zenoh/api/logging.hxx index 0d642a5f..45001fb4 100644 --- a/include/zenoh/api/logging.hxx +++ b/include/zenoh/api/logging.hxx @@ -17,12 +17,23 @@ namespace zenoh { #ifdef ZENOHCXX_ZENOHC -/// @brief Enable logging. +/// @brief Initializes the zenoh runtime logger, using rust environment settings. +/// E.g.: `RUST_LOG=info` will enable logging at info level. Similarly, you can set the variable to `error` or `debug`. +/// Note that if the environment variable is not set, then logging will not be enabled. +/// See https://docs.rs/env_logger/latest/env_logger/index.html for accepted filter format. +/// @note zenoh-c only +inline void try_init_log_from_env() { ::zc_try_init_log_from_env(); } + +/// @brief Initializes the zenoh runtime logger, using rust environment settings or the provided fallback filter. +/// E.g.: `RUST_LOG=info` will enable logging at info level. Similarly, you can set the variable to `error` or `debug`. /// -/// User may set environment variable RUST_LOG to values *debug* | *info* | *warn* | *error* to show diagnostic output. +/// Note that if the environment variable is not set, then fallback filter will be used instead. +/// See https://docs.rs/env_logger/latest/env_logger/index.html for accepted filter format. /// -/// @note zenoh-c only -inline void init_logging() { ::zc_init_logging(); } +/// @param fallback_filter: The fallback filter if the `RUST_LOG` environment variable is not set. +inline void init_log_from_env_or(const std::string& fallback_filter) { + ::zc_init_log_from_env_or(fallback_filter.c_str()); +} #endif } // namespace zenoh \ No newline at end of file diff --git a/tests/zenohc/config.cxx b/tests/zenohc/config.cxx index b6aba6bf..7b45e43b 100644 --- a/tests/zenohc/config.cxx +++ b/tests/zenohc/config.cxx @@ -36,7 +36,7 @@ void test_config_to_string() { } int main(int argc, char** argv) { - init_logging(); + init_log_from_env_or("error"); test_config_insert(); test_config_to_string(); // TODO: add more tests diff --git a/zenoh-c b/zenoh-c index c453da54..280e47e8 160000 --- a/zenoh-c +++ b/zenoh-c @@ -1 +1 @@ -Subproject commit c453da549a0933ba27090bc929e310ca99758b84 +Subproject commit 280e47e8f57af04afe67f0897f3307317d240ed3 diff --git a/zenoh-pico b/zenoh-pico index c5106acd..0a62ea80 160000 --- a/zenoh-pico +++ b/zenoh-pico @@ -1 +1 @@ -Subproject commit c5106acd10c9d43a792b2f615da3a896bc167622 +Subproject commit 0a62ea80b48e2e56e910248fc3fe93180e01af93