diff --git a/CMakeLists.txt b/CMakeLists.txt index 09583056..dfa462de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,10 @@ target_include_directories(plog $ ) +if (ANDROID) + target_link_libraries(plog INTERFACE log) +endif() + add_library(plog::plog ALIAS plog) #making sure we can build standalone under windows diff --git a/include/plog/Appenders/AndroidAppender.h b/include/plog/Appenders/AndroidAppender.h index 8443a326..30f87a22 100644 --- a/include/plog/Appenders/AndroidAppender.h +++ b/include/plog/Appenders/AndroidAppender.h @@ -1,6 +1,8 @@ #pragma once #include +#ifdef ANDROID #include +#endif namespace plog { @@ -12,6 +14,7 @@ namespace plog { } +#ifdef ANDROID virtual void write(const Record& record) { std::string str = Formatter::format(record); @@ -40,6 +43,12 @@ namespace plog return ANDROID_LOG_UNKNOWN; } } +#else + virtual void write(const Record&) + { + // no-op + } +#endif private: const char* const m_tag; diff --git a/samples/AndroidCmake/CMakeLists.txt b/samples/AndroidCmake/CMakeLists.txt new file mode 100644 index 00000000..a4a66a57 --- /dev/null +++ b/samples/AndroidCmake/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(AndroidCmake Main.cpp) +target_link_libraries(AndroidCmake plog) +set_target_properties(AndroidCmake PROPERTIES FOLDER Samples) diff --git a/samples/AndroidCmake/Main.cpp b/samples/AndroidCmake/Main.cpp new file mode 100644 index 00000000..1ac12100 --- /dev/null +++ b/samples/AndroidCmake/Main.cpp @@ -0,0 +1,24 @@ +// +// AndroidAppender - shows how to use an Android appender. +// + +#include +#include +#include +#include + +int main() +{ + static plog::AndroidAppender androidAppender("app"); + plog::init(plog::verbose, &androidAppender); + + // Log severity levels are printed in different colors. + PLOG_VERBOSE << "This is a VERBOSE message"; + PLOG_DEBUG << "This is a DEBUG message"; + PLOG_INFO << "This is an INFO message"; + PLOG_WARNING << "This is a WARNING message"; + PLOG_ERROR << "This is an ERROR message"; + PLOG_FATAL << "This is a FATAL message"; + + return 0; +} diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 28e93022..e9004e14 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -40,6 +40,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) endif() add_subdirectory(Android) +add_subdirectory(AndroidCmake) add_subdirectory(Chained) add_subdirectory(ColorConsole) add_subdirectory(CustomAppender)