diff --git a/universal7885-common/apps/aidl-support/include/LogFormat.h b/universal7885-common/apps/aidl-support/include/LogFormat.h index 18c4627..e772bb3 100644 --- a/universal7885-common/apps/aidl-support/include/LogFormat.h +++ b/universal7885-common/apps/aidl-support/include/LogFormat.h @@ -1,8 +1,19 @@ #include #include +#ifdef LOG_TAG + +#include + #define make_str(a, ...) _make_str(__FILE__, __LINE__, a, ##__VA_ARGS__).c_str() +// Helpers to avoid -Wformat-security +#define LOG_E(fmt, ...) ALOGE("%s", make_str(fmt, ##__VA_ARGS__)) +#define LOG_W(fmt, ...) ALOGW("%s", make_str(fmt, ##__VA_ARGS__)) +#define LOG_I(fmt, ...) ALOGI("%s", make_str(fmt, ##__VA_ARGS__)) +#define LOG_D(fmt, ...) ALOGD("%s", make_str(fmt, ##__VA_ARGS__)) +#define LOG_V(fmt, ...) ALOGV("%s", make_str(fmt, ##__VA_ARGS__)) + template std::string _make_str(const std::string& filename, int line, const std::string& fmt, Args... args) { #pragma clang diagnostic push @@ -14,4 +25,16 @@ std::string _make_str(const std::string& filename, int line, const std::string& std::stringstream ss; ss << "[" << filename << ":" << line << "] " << std::string(buf.begin(), buf.end()); return ss.str(); -} +} + +#else + +#warning LOG_TAG is not defined, disabling logging. + +#define LOG_E(...) do {} while(0) +#define LOG_W(...) do {} while(0) +#define LOG_I(...) do {} while(0) +#define LOG_D(...) do {} while(0) +#define LOG_V(...) do {} while(0) + +#endif