Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test-embedding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmake/MatsdkOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions docs/embedding-with-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions lib/android_build/maesdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/include/mat/config-default.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,4 +53,3 @@
//#define HAVE_CS4
//#define HAVE_CS4_FULL
//#define HAVE_ONEDS_BOUNDCHECK_METHODS

52 changes: 34 additions & 18 deletions lib/jni/LogManager_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<jstring>(k);
Expand All @@ -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));
Expand Down Expand Up @@ -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<jstring>(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<jstring>(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");
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/pal/PAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <windows.h>
#endif

#ifdef ANDROID
#if defined(ANDROID) && defined(HAVE_MAT_LOGGING)
#include <android/log.h>
#endif

Expand Down Expand Up @@ -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<std::thread::id, pid_t> threads;
static long int gettid()
Expand All @@ -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
Expand All @@ -202,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,
Expand Down
2 changes: 1 addition & 1 deletion lib/pal/TaskDispatcher_CAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...) {
Expand Down Expand Up @@ -164,4 +165,3 @@ namespace PAL_NS_BEGIN {
}

} PAL_NS_END

2 changes: 1 addition & 1 deletion lib/pal/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...) {
Expand Down Expand Up @@ -275,4 +276,3 @@ namespace PAL_NS_BEGIN {
} PAL_NS_END

#endif

Loading