Skip to content

Commit

Permalink
Activate Zenoh logs by default (#246)
Browse files Browse the repository at this point in the history
* Activate Zenoh logs at 'warn' level by default

* Set Router default log level to 'info'

* fix code style

* move const definitions into detail/zenoh_config.hpp

* Fix return in rmw_init

Signed-off-by: Yadunund <[email protected]>

---------

Signed-off-by: Yadunund <[email protected]>
Co-authored-by: Yadunund <[email protected]>
  • Loading branch information
JEnoch and Yadunund authored Jul 17, 2024
1 parent de50434 commit ca79e0e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rmw_zenoh_cpp/src/detail/zenoh_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

#include "rmw/ret_types.h"

#define ZENOH_LOG_ENV_VAR_STR "RUST_LOG"
#define ZENOH_LOG_WARN_LEVEL_STR "warn"
#define ZENOH_LOG_INFO_LEVEL_STR "info"

namespace rmw_zenoh_cpp
{
///=============================================================================
Expand Down
8 changes: 8 additions & 0 deletions rmw_zenoh_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ rmw_init(const rmw_init_options_t * options, rmw_context_t * context)
// Initialize context's implementation
context->impl->is_shutdown = false;

// If not already defined, set the logging environment variable for Zenoh sessions
// to warning level by default.
// TODO(Yadunund): Switch to rcutils_get_env once it supports not overwriting values.
if (setenv(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_WARN_LEVEL_STR, 0) != 0) {
RMW_SET_ERROR_MSG("Error configuring Zenoh logging.");
return RMW_RET_ERROR;
}

// Initialize the zenoh configuration.
z_owned_config_t config;
if ((ret =
Expand Down
8 changes: 8 additions & 0 deletions rmw_zenoh_cpp/src/zenohd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ int main(int argc, char ** argv)
(void)argc;
(void)argv;

// If not already defined, set the logging environment variable for Zenoh router
// to info level by default.
// TODO(Yadunund): Switch to rcutils_get_env once it supports not overwriting values.
if (setenv(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_INFO_LEVEL_STR, 0) != 0) {
RMW_SET_ERROR_MSG("Error configuring Zenoh logging.");
return 1;
}

// Initialize the zenoh configuration for the router.
z_owned_config_t config;
if ((rmw_zenoh_cpp::get_z_config(
Expand Down

0 comments on commit ca79e0e

Please sign in to comment.