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

Discussion/Enhancement: Use ANDROID macro definition in AndroidAppender #186

Open
rockaport opened this issue Apr 5, 2021 · 0 comments
Open

Comments

@rockaport
Copy link

When building with the Android NDK it automatically adds a -DANDROID definition to {C/CXX}FLAGS and it can be used to nop calls to android_log on non-android targets.

Right now I'm building a library that sets up several appenders and I'm handling adding the AndroidAppender using the ANDROID definition shown below. It's a small point, but It would be nice to clean this up and push these conditions into the AndroidAppender. It would just be a nop if it's being run on a non-Android target.

I don't even think a compile warning is necessary if you're compiling in an AndroidAppender for a non-Android target.

I'm already handling the linking of plog/log using a cmake interface and there's two places I need to manage this. I guess this could get pushed into plog/CMakeLists.txt too?

# logger.cmake
add_library(logger INTERFACE)
target_link_libraries(logger INTERFACE plog)
if (ANDROID)
    target_link_libraries(logger INTERFACE log)
endif ()

# CMakeLists.txt
include(logger.cmake)
target_link_libraries(${PROJECT_NAME} PUBLIC logger)
// some-file.cpp
#ifdef ANDROID
#include <plog/Appenders/AndroidAppender.h>
#endif

void foo::initLogger() {
    plog::init(plog::debug);

    static plog::ColorConsoleAppender<plog::TxtFormatter> colorConsoleAppender;
    plog::get()->addAppender(&colorConsoleAppender);

    #if ANDROID
        static plog::AndroidAppender<plog::TxtFormatter> androidAppender("app");
        plog::get()->addAppender(&androidAppender);
    #endif
}
rockaport added a commit to rockaport/plog that referenced this issue May 2, 2021
- Add #ifdef's on ANDROID for AndroidAppender.h and automatically link Android's log library if targeting Android
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants