Skip to content

Commit

Permalink
Merge pull request #683 from eclipse-zenoh/dev/init_log_from_env_or
Browse files Browse the repository at this point in the history
dev/init log from env or
  • Loading branch information
Mallets authored Sep 13, 2024
2 parents 20580b8 + 8024df7 commit 280e47e
Show file tree
Hide file tree
Showing 44 changed files with 669 additions and 453 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
cd .. && rm -rf build_examples
- name: Run rust tests
run: cargo test --verbose --release --features=logger-autoinit
run: cargo test --verbose --release

- name: Upload artifact
if: ${{ matrix.unstable == 'false' && matrix.shm == 'false' }}
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build:
jobs:
# Run cargo build to build git ignored files that are platform specific (e.g. include/zenoh_opaque.h)
pre_build:
- cargo build --release --manifest-path=./Cargo.toml --features=logger-autoinit --features=unstable --features=shared-memory
- cargo build --release --manifest-path=./Cargo.toml --features=unstable --features=shared-memory


# Build documentation in the docs/ directory with Sphinx
Expand Down
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ enable_testing()
# Configuration options
#
declare_cache_var_true_if_vscode(ZENOHC_BUILD_IN_SOURCE_TREE "Do build inside source tree")
declare_cache_var(ZENOHC_BUILD_WITH_LOGGER_AUTOINIT TRUE BOOL "Enable logger-autoinit zenoh-c feature")
declare_cache_var(ZENOHC_BUILD_WITH_SHARED_MEMORY FALSE BOOL "Enable shared-memory zenoh-c feature")
declare_cache_var(ZENOHC_BUILD_WITH_UNSTABLE_API FALSE BOOL "Enable unstable API feature")
declare_cache_var(ZENOHC_BUILD_TESTS_WITH_CXX FALSE BOOL "Use C++ compiler for building tests to check API's C++ compatibility")
Expand Down Expand Up @@ -200,10 +199,6 @@ set_genexpr_condition(cargo_flags DEBUG $<CONFIG:Debug>
"--release;--manifest-path=${cargo_toml_dir_release}/Cargo.toml")
set(cargo_flags ${cargo_flags} ${ZENOHC_CARGO_FLAGS})

if(ZENOHC_BUILD_WITH_LOGGER_AUTOINIT)
set(cargo_flags ${cargo_flags} --features=logger-autoinit)
endif()

if(ZENOHC_BUILD_WITH_SHARED_MEMORY)
set(cargo_flags ${cargo_flags} --features=shared-memory)
endif()
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
logger-autoinit = []
shared-memory = ["zenoh/shared-memory", "dep:zenoh-ext", "zenoh-ext/shared-memory"]
unstable = ["zenoh/unstable", "zenoh-ext/unstable", "dep:zenoh-ext"]
default = ["zenoh/default"]
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ build = "@[email protected]"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
logger-autoinit = []
shared-memory = ["zenoh/shared-memory", "dep:zenoh-ext", "zenoh-ext/shared-memory"]
unstable = ["zenoh/unstable", "zenoh-ext/unstable", "dep:zenoh-ext"]
default = ["zenoh/default"]
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ Finally, we strongly advise that you refrain from using structure field that sta
- We try to maintain a common API between `zenoh-c` and [`zenoh-pico`](https://github.com/eclipse-zenoh/zenoh-pico), such that porting code from one to the other is, ideally, trivial. However, some types must have distinct representations in either library, meaning that using these representations explicitly will get you in trouble when porting.
- We reserve the right to change the memory layout of any type which has `_`-prefixed fields, so trying to use them might cause your code to break on updates.

## Logging

By default, zenoh-c enables Zenoh's logging library upon using the `z_open` or `z_scout` functions. This behavior can be disabled by adding `-DDISABLE_LOGGER_AUTOINIT:bool=true` to the `cmake` configuration command. The logger may then be manually re-enabled with the `zc_init_logging` function.

## Cross-Compilation

The following alternative options have been introduced to facilitate cross-compilation.
Expand Down
3 changes: 2 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@ Types
Functions
---------

.. doxygenfunction:: zc_init_logging
.. doxygenfunction:: zc_try_init_log_from_env
.. doxygenfunction:: zc_init_log_from_env_or
.. doxygenfunction:: zc_init_logging_with_callback


Expand Down
2 changes: 2 additions & 0 deletions examples/z_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_get_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
3 changes: 3 additions & 0 deletions examples/z_get_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ int main(int argc, char** argv) {
}
size_t value_len = value ? strlen(value) : 0;

zc_init_log_from_env_or("error");

z_view_keyexpr_t keyexpr;
if (z_view_keyexpr_from_str(&keyexpr, expr) < 0) {
printf("%s is not a valid key expression", expr);
exit(-1);
}

z_owned_config_t config;
z_config_default(&config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void print_zid(const z_id_t* id, void* ctx) {
void parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_non_blocking_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
3 changes: 3 additions & 0 deletions examples/z_ping_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ int main(int argc, char** argv) {
}
z_mutex_init(&mutex);
z_condvar_init(&cond);

zc_init_log_from_env_or("error");

z_owned_config_t config;
if (args.config_path) {
zc_config_from_file(&config, args.config_path);
Expand Down
2 changes: 2 additions & 0 deletions examples/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void drop(void* context) {
}

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void matching_status_handler(const zc_matching_status_t* matching_status, void*
#endif

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_pub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_pub_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_pub_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void matching_status_handler(const zc_matching_status_t* matching_status, void*
#endif

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_pub_shm_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ int main(int argc, char **argv) {
char *keyexpr = "test/thr";
size_t len = atoi(argv[1]);

zc_init_log_from_env_or("error");

z_owned_config_t config;
z_config_default(&config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_pub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);
int main(int argc, char** argv) {
char* keyexpr = "test/thr";

zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);
uint8_t* value = (uint8_t*)z_malloc(args.size);
Expand Down
2 changes: 2 additions & 0 deletions examples/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void handle_sample(const z_loaned_sample_t* sample) {
}

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_query_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void data_handler(z_loaned_sample_t* sample, void* arg) {
}

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void query_handler(z_loaned_query_t *query, void *context) {
}

int main(int argc, char **argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);
value = args.value;
Expand Down
3 changes: 3 additions & 0 deletions examples/z_queryable_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ int main(int argc, char **argv) {
if (argc > 1) {
keyexpr = argv[1];
}

zc_init_log_from_env_or("error");

z_owned_config_t config;
z_config_default(&config);
if (argc > 2) {
Expand Down
2 changes: 2 additions & 0 deletions examples/z_queryable_with_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);
z_view_keyexpr_t ke;

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void drop(void *context) {
}

int main(int argc, char **argv) {
zc_init_log_from_env_or("error");

int *context = z_malloc(sizeof(int));
*context = 0;
z_owned_config_t config;
Expand Down
2 changes: 2 additions & 0 deletions examples/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void data_handler(z_loaned_sample_t *sample, void *arg) {
}

int main(int argc, char **argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);
z_view_keyexpr_t ke;
Expand Down
2 changes: 2 additions & 0 deletions examples/z_sub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void data_handler(z_loaned_sample_t* sample, void* arg) {
}

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);
z_view_keyexpr_t ke;
Expand Down
2 changes: 2 additions & 0 deletions examples/z_sub_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void data_handler(z_loaned_sample_t* sample, void* arg) {
}

int main(int argc, char** argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
struct args_t args = parse_args(argc, argv, &config);
z_view_keyexpr_t ke;
Expand Down
2 changes: 2 additions & 0 deletions examples/z_sub_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ int main(int argc, char **argv) {
keyexpr = argv[1];
}

zc_init_log_from_env_or("error");

z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, keyexpr);

Expand Down
2 changes: 2 additions & 0 deletions examples/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void drop_stats(void *context) {
}

int main(int argc, char **argv) {
zc_init_log_from_env_or("error");

z_owned_config_t config;
parse_args(argc, argv, &config);

Expand Down
Loading

0 comments on commit 280e47e

Please sign in to comment.