From 0c53ab7dbe9d6933f38fce2119d03c341af34799 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Thu, 10 Sep 2026 01:58:58 -0500 Subject: [PATCH 1/3] Allow embedded builds to compile out internal logging Expose MATSDK_DISABLE_LOGGING so consumers can remove diagnostic logging without patching 1DS or disabling telemetry upload. Files changed: - CMake option and internal target configuration - default logging feature selection and PAL warning fixes - embedding documentation and CI coverage Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 49c171ca-76ba-4688-afaf-df59129cda4f --- .github/workflows/test-embedding.yml | 4 ++++ CMakeLists.txt | 4 ++++ cmake/MatsdkOptions.cmake | 2 ++ docs/embedding-with-cmake.md | 3 +++ lib/include/mat/config-default.h | 3 ++- lib/pal/PAL.cpp | 2 ++ lib/pal/TaskDispatcher_CAPI.cpp | 2 +- lib/pal/WorkerThread.cpp | 2 +- 8 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-embedding.yml b/.github/workflows/test-embedding.yml index 0565a1c86..d767bfeec 100644 --- a/.github/workflows/test-embedding.yml +++ b/.github/workflows/test-embedding.yml @@ -31,18 +31,21 @@ jobs: fetchcontent: OFF preload-curl: ON preload-storage: ON + disable-logging: OFF - dependencies: system library-type: SHARED shared: ON fetchcontent: ON preload-curl: OFF preload-storage: OFF + disable-logging: OFF - dependencies: self-contained library-type: STATIC shared: OFF fetchcontent: ON preload-curl: OFF preload-storage: OFF + disable-logging: ON steps: - uses: actions/checkout@v4 - name: Install system dependencies @@ -59,6 +62,7 @@ jobs: -DMATSDK_EMBEDDING_USE_FETCHCONTENT=${{ matrix.fetchcontent }} -DMATSDK_EMBEDDING_PRELOAD_CURL=${{ matrix.preload-curl }} -DMATSDK_EMBEDDING_PRELOAD_STORAGE_DEPS=${{ matrix.preload-storage }} + -DMATSDK_DISABLE_LOGGING=${{ matrix.disable-logging }} -DBUILD_SHARED_LIBS=${{ matrix.shared }} ) if [[ "${{ matrix.dependencies }}" == "self-contained" ]]; then diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d3a0c9c5..cf1777eda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,10 @@ add_library(matsdk_internal_config INTERFACE) target_compile_definitions(matsdk_internal_config INTERFACE MATSDK_PAL_${PAL_IMPLEMENTATION_UPPER}=1 NOMINMAX) +if(MATSDK_DISABLE_LOGGING) + target_compile_definitions(matsdk_internal_config INTERFACE + MATSDK_DISABLE_LOGGING) +endif() option(GCC5_CXX11_ABI_WORKAROUND "Workaround: Use legacy C++11 ABI (for GCC 5 compatibility)" OFF) if(GCC5_CXX11_ABI_WORKAROUND) diff --git a/cmake/MatsdkOptions.cmake b/cmake/MatsdkOptions.cmake index a56e468c6..51a8d7d98 100644 --- a/cmake/MatsdkOptions.cmake +++ b/cmake/MatsdkOptions.cmake @@ -42,6 +42,8 @@ option(MATSDK_BUILD_AZMON "Build Azure Monitor / Application Insights support" ON) option(MATSDK_BUILD_APPLE_HTTP "Build the Apple-native HTTP client" "${APPLE}") +option(MATSDK_DISABLE_LOGGING + "Compile internal SDK logging out" OFF) set(_matsdk_android_http_client_predefined OFF) if(DEFINED MATSDK_ANDROID_HTTP_CLIENT) diff --git a/docs/embedding-with-cmake.md b/docs/embedding-with-cmake.md index 3d9f1c591..7a3d08a33 100644 --- a/docs/embedding-with-cmake.md +++ b/docs/embedding-with-cmake.md @@ -26,6 +26,9 @@ SDK-specific behavior continues to use namespaced `MATSDK_*` options. targets and never propagates to the parent consumer or vendored dependencies. Set it explicitly to `ON` in consumer CI to test new toolchains strictly. +Set `MATSDK_DISABLE_LOGGING=ON` to compile the SDK's internal diagnostic +logging out. This does not disable telemetry event collection or upload. + ## SQLite and zlib providers Source builds can select dependency modes without patching 1DS sources: diff --git a/lib/include/mat/config-default.h b/lib/include/mat/config-default.h index 2ddce7dfc..e5a094f1a 100644 --- a/lib/include/mat/config-default.h +++ b/lib/include/mat/config-default.h @@ -28,7 +28,9 @@ #endif #define HAVE_MAT_JSONHPP #define HAVE_MAT_ZLIB +#if !defined(MATSDK_DISABLE_LOGGING) #define HAVE_MAT_LOGGING +#endif /* #define HAVE_MAT_WIN_LOG */ /* #define HAVE_MAT_EVT_TRACEID */ #define HAVE_MAT_STORAGE @@ -51,4 +53,3 @@ //#define HAVE_CS4 //#define HAVE_CS4_FULL //#define HAVE_ONEDS_BOUNDCHECK_METHODS - diff --git a/lib/pal/PAL.cpp b/lib/pal/PAL.cpp index 0fc28abfb..4d3368d22 100644 --- a/lib/pal/PAL.cpp +++ b/lib/pal/PAL.cpp @@ -183,6 +183,7 @@ namespace PAL_NS_BEGIN { #endif #if !defined(_WIN32) && defined(__linux__) +#ifdef HAVE_MAT_LOGGING static std::mutex m; static std::map threads; static long int gettid() @@ -192,6 +193,7 @@ namespace PAL_NS_BEGIN { threads[std::this_thread::get_id()] = tid; return tid; } +#endif #else #define gettid() std::this_thread::get_id() #endif diff --git a/lib/pal/TaskDispatcher_CAPI.cpp b/lib/pal/TaskDispatcher_CAPI.cpp index e75ee1924..0257d7de6 100644 --- a/lib/pal/TaskDispatcher_CAPI.cpp +++ b/lib/pal/TaskDispatcher_CAPI.cpp @@ -45,6 +45,7 @@ namespace PAL_NS_BEGIN { (*m_task)(); } catch (const std::exception& ex) { + (void)ex; LOG_ERROR("Unhandled exception in CAPI task: %s", ex.what()); } catch (...) { @@ -164,4 +165,3 @@ namespace PAL_NS_BEGIN { } } PAL_NS_END - diff --git a/lib/pal/WorkerThread.cpp b/lib/pal/WorkerThread.cpp index 3adfb9e61..07166958c 100644 --- a/lib/pal/WorkerThread.cpp +++ b/lib/pal/WorkerThread.cpp @@ -248,6 +248,7 @@ namespace PAL_NS_BEGIN { (*item)(); } catch (const std::exception& ex) { + (void)ex; LOG_ERROR("Unhandled exception in worker task: %s", ex.what()); } catch (...) { @@ -275,4 +276,3 @@ namespace PAL_NS_BEGIN { } PAL_NS_END #endif - From a5acf2ad993965a4569e2758a484b4fbbc772cf3 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Thu, 10 Sep 2026 11:31:20 -0500 Subject: [PATCH 2/3] Disable Android Logcat with internal logging Honor MATSDK_DISABLE_LOGGING in the Android PAL path so embedded builds do not retain internal Logcat output or its header dependency. Files changed: - lib/pal/PAL.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- lib/pal/PAL.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pal/PAL.cpp b/lib/pal/PAL.cpp index 4d3368d22..eac02482a 100644 --- a/lib/pal/PAL.cpp +++ b/lib/pal/PAL.cpp @@ -50,7 +50,7 @@ #include #endif -#ifdef ANDROID +#if defined(ANDROID) && defined(HAVE_MAT_LOGGING) #include #endif @@ -204,7 +204,7 @@ namespace PAL_NS_BEGIN { #endif void log(LogLevel level, char const* component, char const* fmt, ...) { -#if defined(ANDROID) && !defined(ANDROID_SUPPRESS_LOGCAT) +#if defined(ANDROID) && defined(HAVE_MAT_LOGGING) && !defined(ANDROID_SUPPRESS_LOGCAT) { static android_LogPriority androidPriorities[] = { ANDROID_LOG_UNKNOWN, From 7e905a9ff9959fa0bd9232d76a9539c5988ab9e4 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Thu, 10 Sep 2026 13:56:03 -0500 Subject: [PATCH 3/3] Compile Android JNI diagnostics out Honor MATSDK_DISABLE_LOGGING across the JNI wrapper and remove the unused liblog dependency so Android embedding builds retain no internal Logcat path. Files changed: - lib/CMakeLists.txt - lib/android_build/maesdk/build.gradle - lib/jni/LogManager_jni.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0ab71a08-8e5c-4fdd-ae7e-466debb4860f --- lib/CMakeLists.txt | 2 +- lib/android_build/maesdk/build.gradle | 2 ++ lib/jni/LogManager_jni.cpp | 52 +++++++++++++++++---------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b08fd4537..063b48efb 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -662,7 +662,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l") target_link_libraries(mat PUBLIC atomic) endif() - if(CMAKE_SYSTEM_NAME STREQUAL "Android") + if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND NOT MATSDK_DISABLE_LOGGING) target_link_libraries(mat PUBLIC log) endif() elseif(PAL_IMPLEMENTATION STREQUAL "WIN32") diff --git a/lib/android_build/maesdk/build.gradle b/lib/android_build/maesdk/build.gradle index 23d3a732b..9a043215e 100644 --- a/lib/android_build/maesdk/build.gradle +++ b/lib/android_build/maesdk/build.gradle @@ -20,6 +20,8 @@ android { args.add("-DBUILD_SHARED_LIBS=ON") args.add("-DMATSDK_ANDROID_USE_ROOM=ON") args.add("-DMATSDK_BUILD_JNI_WRAPPER=ON") + String disableLogging = project.findProperty("MATSDK_DISABLE_LOGGING") ?: "OFF" + args.add("-DMATSDK_DISABLE_LOGGING=" + disableLogging) args.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON") String linkerFlag = project.findProperty("CMAKE_SHARED_LINKER_FLAGS") ?: "" linkerFlag = "-DCMAKE_SHARED_LINKER_FLAGS=" + linkerFlag diff --git a/lib/jni/LogManager_jni.cpp b/lib/jni/LogManager_jni.cpp index c6a0b6213..22b4244ee 100644 --- a/lib/jni/LogManager_jni.cpp +++ b/lib/jni/LogManager_jni.cpp @@ -30,7 +30,9 @@ #include "JniConvertors.hpp" #include "LogManagerBase.hpp" #include "WrapperLogManager.hpp" +#ifdef HAVE_MAT_LOGGING #include "android/log.h" +#endif #include "config/RuntimeConfig_Default.hpp" using namespace MAT; @@ -578,15 +580,19 @@ namespace rethrow(env); if (k == nullptr) { +#ifdef HAVE_MAT_LOGGING __android_log_print(ANDROID_LOG_ERROR, "MAE", "Null configuration key"); +#endif continue; } if (!env->IsInstanceOf(k, stringClass)) { +#ifdef HAVE_MAT_LOGGING __android_log_print(ANDROID_LOG_ERROR, "MAE", "Configuration key is not a string"); +#endif continue; } auto key = static_cast(k); @@ -600,11 +606,13 @@ namespace rethrow(env); if (!value) { +#ifdef HAVE_MAT_LOGGING __android_log_print( ANDROID_LOG_WARN, "MAE", "Null value for key %s in translateVariantMap", stringKey.c_str()); +#endif } auto v = translateVariant(value); auto emplace = variantMap.emplace(stringKey, std::move(v)); @@ -674,27 +682,31 @@ namespace } } // if class matches } // for (... classCache){ - auto actual = env->GetObjectClass(value); - auto meta = env->GetObjectClass(actual); - rethrow(env); - auto gnMethod = - env->GetMethodID(meta, - "getName", - "()Ljava/lang/String;"); - rethrow(env); - auto jName = - static_cast(env->CallObjectMethod(actual, - gnMethod)); - std::string className; - if (!TryJStringToStdString(env, jName, className)) +#ifdef HAVE_MAT_LOGGING { + auto actual = env->GetObjectClass(value); + auto meta = env->GetObjectClass(actual); + rethrow(env); + auto gnMethod = + env->GetMethodID(meta, + "getName", + "()Ljava/lang/String;"); rethrow(env); - throw std::runtime_error("Unable to convert class name"); + auto jName = + static_cast(env->CallObjectMethod(actual, + gnMethod)); + std::string className; + if (!TryJStringToStdString(env, jName, className)) + { + rethrow(env); + throw std::runtime_error("Unable to convert class name"); + } + __android_log_print(ANDROID_LOG_ERROR, + "MAE", + "Unsupported class %s", + className.c_str()); } - __android_log_print(ANDROID_LOG_ERROR, - "MAE", - "Unsupported class %s", - className.c_str()); +#endif auto errorClass = env->FindClass("java/lang/Error"); rethrow(env); env->ThrowNew(errorClass, "Unsupported class"); @@ -881,10 +893,12 @@ Java_com_microsoft_applications_events_LogManager_nativeInitializeConfig(JNIEnv* ILogConfiguration logConfiguration; VariantTranslator variantTranslator(env); variantTranslator.translateVariantMap(*logConfiguration, configuration); +#ifdef HAVE_MAT_LOGGING std::string cereal; Variant::serialize(*logConfiguration, cereal); __android_log_print(ANDROID_LOG_INFO, "MAE", "Translated map: %s", cereal.c_str()); +#endif std::string token; if (!TryJStringToStdString(env, tenant_token, token)) @@ -928,9 +942,11 @@ Java_com_microsoft_applications_events_LogManagerProvider_nativeCreateLogManager jniManagers.emplace_back(std::move(mcPointer)); return n; } +#ifdef HAVE_MAT_LOGGING __android_log_print(ANDROID_LOG_ERROR, "MAE", "Failed to create log manager"); +#endif return -1; }