Add getter for the current log level. (#5807)

The getter is useful if a module outputs debug logs buts also some updated status update in a single line with rz_cons_printf("\r...").
The status update should not happen if the log level is below warning.
This commit is contained in:
Rot127 2026-01-23 18:52:45 +00:00 committed by GitHub
parent 7d34c4d914
commit 4675f5cafe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 0 deletions

View file

@ -60,6 +60,7 @@ extern "C" {
#endif
// Called by rz_core to set the configuration variables
RZ_API RzLogLevel rz_log_get_level();
RZ_API void rz_log_set_level(RzLogLevel level);
RZ_API void rz_log_set_abortlevel(RzLogLevel level);
RZ_API bool rz_log_set_file(RZ_NULLABLE const char *filename);

View file

@ -68,6 +68,16 @@ RZ_API void rz_log_set_level(RzLogLevel level) {
rz_th_lock_leave(logcfg.lock);
}
/**
* \brief Gets the log level
*
* \param[in] level The current log level.
*/
RZ_API RzLogLevel rz_log_get_level() {
log_init();
return logcfg.level;
}
/**
* \brief Sets the log level when to abort execution
*

View file

@ -56,10 +56,21 @@ bool test_log_large(void) {
mu_end;
}
bool test_log_set_get(void) {
rz_log_del_callback((RzLogCallback)small_check);
rz_log_del_callback((RzLogCallback)bind_check);
rz_log_set_level(RZ_LOGLVL_FATAL);
mu_assert_eq(rz_log_get_level(), RZ_LOGLVL_FATAL, "Setter/Getter");
rz_log_set_level(RZ_LOGLVL_DEBUG);
mu_assert_eq(rz_log_get_level(), RZ_LOGLVL_DEBUG, "Setter/Getter");
mu_end;
}
bool all_tests() {
mu_run_test(test_log_small);
mu_run_test(test_log_binding);
mu_run_test(test_log_large);
mu_run_test(test_log_set_get);
return tests_passed != tests_run;
}