Skip to content

Commit

Permalink
add log mechanism for Android port
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwg committed Sep 22, 2018
1 parent 841ce12 commit f026596
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,17 @@ if(BUILD_WITH_TM2)
endif()
set_target_properties(realsense2 PROPERTIES VERSION ${REALSENSE_VERSION_STRING}
SOVERSION ${REALSENSE_VERSION_MAJOR})
target_link_libraries(realsense2 PRIVATE realsense-file ${CMAKE_THREAD_LIBS_INIT} ${TRACKING_DEVICE_LIBS})

if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
if(BUILD_SHARED_LIBS)
find_library(log-lib log)
target_link_libraries(realsense2 PRIVATE realsense-file ${CMAKE_THREAD_LIBS_INIT} ${TRACKING_DEVICE_LIBS} log)
else()
target_link_libraries(realsense2 PRIVATE realsense-file ${CMAKE_THREAD_LIBS_INIT} ${TRACKING_DEVICE_LIBS})
endif()
else()
target_link_libraries(realsense2 PRIVATE realsense-file ${CMAKE_THREAD_LIBS_INIT} ${TRACKING_DEVICE_LIBS})
endif()

if (NOT USE_SYSTEM_LIBUSB)
if(NOT WIN32)
Expand Down
7 changes: 6 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ if(BUILD_GRAPHICAL_EXAMPLES)
include_directories(${GLFW_INCLUDE_DIR})
endif()
else()
set(DEPENDENCIES realsense2)
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
find_library(log-lib log)
set(DEPENDENCIES realsense2 log)
else()
set(DEPENDENCIES realsense2)
endif()
if(NOT WIN32)
list(APPEND DEPENDENCIES m ${LIBUSB1_LIBRARIES})
endif()
Expand Down
23 changes: 23 additions & 0 deletions third-party/easyloggingpp/src/easylogging++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
//

#include "easylogging++.h"
#ifdef ANDROID
#include <android/log.h>
#endif

#if defined(AUTO_INITIALIZE_EASYLOGGINGPP)
INITIALIZE_EASYLOGGINGPP
Expand Down Expand Up @@ -2094,6 +2097,26 @@ void DefaultLogDispatchCallback::handle(const LogDispatchData* data) {
}

void DefaultLogDispatchCallback::dispatch(base::type::string_t&& logLine) {
#ifdef ANDROID
if (m_data->logMessage()->logger()->m_typedConfigurations->toStandardOutput(m_data->logMessage()->level())) {
int androidLogPriority = ANDROID_LOG_FATAL;
if (m_data->logMessage()->level() == Level::Fatal)
androidLogPriority = ANDROID_LOG_FATAL;
else if (m_data->logMessage()->level() == Level::Error)
androidLogPriority = ANDROID_LOG_ERROR;
else if (m_data->logMessage()->level() == Level::Warning)
androidLogPriority = ANDROID_LOG_WARN;
else if (m_data->logMessage()->level() == Level::Info)
androidLogPriority = ANDROID_LOG_INFO;
else if (m_data->logMessage()->level() == Level::Debug)
androidLogPriority = ANDROID_LOG_DEBUG;
else
androidLogPriority = ANDROID_LOG_FATAL;

__android_log_print(androidLogPriority, "librealsense", "%s", logLine.c_str());
}
#endif

if (m_data->dispatchAction() == base::DispatchAction::NormalLog) {
if (m_data->logMessage()->logger()->m_typedConfigurations->toFile(m_data->logMessage()->level())) {
base::type::fstream_t* fs = m_data->logMessage()->logger()->m_typedConfigurations->fileStream(
Expand Down
7 changes: 6 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ if(BUILD_GRAPHICAL_EXAMPLES)
include_directories(${GLFW_INCLUDE_DIR})
endif()
else()
set(DEPENDENCIES realsense2)
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
find_library(log-lib log)
set(DEPENDENCIES realsense2 log)
else()
set(DEPENDENCIES realsense2)
endif()
if(NOT WIN32)
list(APPEND DEPENDENCIES m ${LIBUSB1_LIBRARIES})
endif()
Expand Down

0 comments on commit f026596

Please sign in to comment.