Skip to content

Commit

Permalink
align logging with zenoh-c
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Sep 13, 2024
1 parent c25dbcd commit c156151
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/commons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ Sample
Logging
-------

.. doxygenfunction:: init_logging
.. doxygenfunction:: try_init_log_from_env
.. doxygenfunction:: init_log_from_env_or
20 changes: 16 additions & 4 deletions include/zenoh/api/logging.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
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.
/// @note zenoh-c only.
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
2 changes: 1 addition & 1 deletion tests/zenohc/config.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zenoh-pico

0 comments on commit c156151

Please sign in to comment.