Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes SergiusTheBest/plog#186 #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ target_include_directories(plog
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

if (ANDROID)
target_link_libraries(plog INTERFACE log)
endif()

add_library(plog::plog ALIAS plog)

#making sure we can build standalone under windows
Expand Down
9 changes: 9 additions & 0 deletions include/plog/Appenders/AndroidAppender.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <plog/Appenders/IAppender.h>
#ifdef ANDROID
#include <android/log.h>
#endif

namespace plog
{
Expand All @@ -12,6 +14,7 @@ namespace plog
{
}

#ifdef ANDROID
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's a good idea to provide an empty implementation of AndroidAppender. It could conceal errors. What do you think?

virtual void write(const Record& record)
{
std::string str = Formatter::format(record);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions samples/AndroidCmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(AndroidCmake Main.cpp)
target_link_libraries(AndroidCmake plog)
set_target_properties(AndroidCmake PROPERTIES FOLDER Samples)
24 changes: 24 additions & 0 deletions samples/AndroidCmake/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// AndroidAppender - shows how to use an Android appender.
//

#include <plog/Log.h>
#include <plog/Init.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Appenders/AndroidAppender.h>

int main()
{
static plog::AndroidAppender<plog::TxtFormatter> 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;
}
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down