This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch feature/490-add-verbose-log-ctrl in repository https://gitbox.apache.org/repos/asf/celix.git
commit 626e23c969e08470a93aacf510959221b43cf117 Author: PengZheng <[email protected]> AuthorDate: Wed May 10 21:56:29 2023 +0800 Add verbosity control to log control service. --- bundles/logging/log_admin/CMakeLists.txt | 2 +- bundles/logging/log_admin/src/celix_log_admin.c | 4 ++-- .../log_helper/gtest/src/LogHelperTestSuite.cc | 2 +- bundles/logging/log_helper/src/celix_log_helper.c | 4 ++-- .../log_service_api/include/celix_log_control.h | 24 ++++++++++++++++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/bundles/logging/log_admin/CMakeLists.txt b/bundles/logging/log_admin/CMakeLists.txt index 5625f400..762439fd 100644 --- a/bundles/logging/log_admin/CMakeLists.txt +++ b/bundles/logging/log_admin/CMakeLists.txt @@ -19,7 +19,7 @@ add_celix_bundle(log_admin SYMBOLIC_NAME "apache_celix_log_admin" NAME "Apache Celix Log Admin" GROUP "Celix/Logging" - VERSION "1.0.0" + VERSION "1.1.0" SOURCES src/celix_log_admin.c src/celix_log_admin_activator.c diff --git a/bundles/logging/log_admin/src/celix_log_admin.c b/bundles/logging/log_admin/src/celix_log_admin.c index 6b4a5af5..70df7d49 100644 --- a/bundles/logging/log_admin/src/celix_log_admin.c +++ b/bundles/logging/log_admin/src/celix_log_admin.c @@ -473,7 +473,7 @@ static void celix_logAdmin_setLogLevelCmd(celix_log_admin_t* admin, const char* size_t count = celix_logAdmin_setActiveLogLevels(admin, select, logLevel); fprintf(outStream, "Updated %lu log services to log level %s\n", (long unsigned int) count, celix_logUtils_logLevelToString(logLevel)); } else { - fprintf(outStream, "Cannot convert '%s' to a valid celix log level.\n", level); + fprintf(errorStream, "Cannot convert '%s' to a valid celix log level.\n", level); } } @@ -491,7 +491,7 @@ static void celix_logAdmin_setSinkEnabledCmd(celix_log_admin_t* admin, const cha size_t count = celix_logAdmin_setSinkEnabled(admin, select, enableSink); fprintf(outStream, "Updated %lu log sinks to %s.\n", (long unsigned int) count, enableSink ? "enabled" : "disabled"); } else { - fprintf(outStream, "Cannot convert '%s' to a boolean value.\n", enabled); + fprintf(errorStream, "Cannot convert '%s' to a boolean value.\n", enabled); } } diff --git a/bundles/logging/log_helper/gtest/src/LogHelperTestSuite.cc b/bundles/logging/log_helper/gtest/src/LogHelperTestSuite.cc index 1ba728cf..f45a1528 100644 --- a/bundles/logging/log_helper/gtest/src/LogHelperTestSuite.cc +++ b/bundles/logging/log_helper/gtest/src/LogHelperTestSuite.cc @@ -65,7 +65,7 @@ TEST_F(LogHelperTestSuite, LogToLogSvc) { std::atomic<size_t> logCount{0}; celix_log_service_t logSvc; logSvc.handle = (void*)&logCount; - logSvc.vlog = [](void *handle, celix_log_level_e, const char *format, va_list formatArgs) { + logSvc.vlogDetails= [](void *handle, celix_log_level_e, const char*, const char*, int, const char *format, va_list formatArgs) { auto* c = static_cast<std::atomic<size_t>*>(handle); c->fetch_add(1); vfprintf(stderr, format, formatArgs); diff --git a/bundles/logging/log_helper/src/celix_log_helper.c b/bundles/logging/log_helper/src/celix_log_helper.c index 1519b41b..7b9fe441 100644 --- a/bundles/logging/log_helper/src/celix_log_helper.c +++ b/bundles/logging/log_helper/src/celix_log_helper.c @@ -151,10 +151,10 @@ void celix_logHelper_vlogDetails(celix_log_helper_t* logHelper, celix_log_level_ celixThreadMutex_lock(&logHelper->mutex); celix_log_service_t* ls = logHelper->logService; if (ls != NULL) { - ls->vlog(ls->handle, level, format, formatArgs); + ls->vlogDetails(ls->handle, level, file, function, line, format, formatArgs); } else { //falling back on stdout/stderr - celix_logUtils_vLogToStdout(logHelper->logServiceName, level, format, formatArgs); + celix_logUtils_vLogToStdoutDetails(logHelper->logServiceName, level, file, function, line, format, formatArgs); } logHelper->logCount += 1; celixThreadMutex_unlock(&logHelper->mutex); diff --git a/bundles/logging/log_service_api/include/celix_log_control.h b/bundles/logging/log_service_api/include/celix_log_control.h index b7c8fe84..2123357d 100644 --- a/bundles/logging/log_service_api/include/celix_log_control.h +++ b/bundles/logging/log_service_api/include/celix_log_control.h @@ -20,6 +20,7 @@ #ifndef CELIX_LOG_CONTROL_H #define CELIX_LOG_CONTROL_H +#include <stdbool.h> #include "celix_log_level.h" #include "celix_array_list.h" @@ -28,8 +29,8 @@ extern "C" { #endif #define CELIX_LOG_CONTROL_NAME "celix_log_control" -#define CELIX_LOG_CONTROL_VERSION "1.0.0" -#define CELIX_LOG_CONTROL_USE_RANGE "[1.0.0,2)" +#define CELIX_LOG_CONTROL_VERSION "1.1.0" +#define CELIX_LOG_CONTROL_USE_RANGE "[1.1.0,2)" typedef struct celix_log_control { void *handle; @@ -50,6 +51,25 @@ typedef struct celix_log_control { bool (*sinkInfo)(void *handle, const char* sinkName, bool *outEnabled); + /** + * @brief Enable/disable verbose mode for selected loggers. + * @param[in] handle The service handle. + * @param[in] select The select string that specifies the case-insensitive name prefix of target loggers. + * @param[in] verbose True to enable verbose mode, false to disable verbose mode. + * @return Number of logger selected. + */ + size_t (*setVerbose)(void *handle, const char* select, bool verbose); + + /** + * @brief Get the active log level and the verbose mode for a selected logger. + * @param [in] handle The service handle. + * @param [in] loggerName The name of the target logger. + * @param [out] outActiveLogLevel The active log level of the target logger. + * @param [out] outVerbose The verbose mode of the target logger. + * @return True if the target logger is found, false otherwise. + */ + bool (*logServiceInfoEx)(void *handle, const char* loggerName, celix_log_level_e* outActiveLogLevel, bool* outVerbose); + } celix_log_control_t; #ifdef __cplusplus
