universal7885: aidl-support: Add a common header for log format

This commit is contained in:
roynatech2544 2022-10-22 22:56:22 +09:00
commit b5a6677f60
2 changed files with 19 additions and 0 deletions

View file

@ -0,0 +1,5 @@
cc_library_headers {
name: "logformat",
local_include_dirs: ["include"],
export_include_dirs: ["include"],
}

View file

@ -0,0 +1,14 @@
#include <sstream>
#include <vector>
#define make_str(a, ...) _make_str(__FILE__, __LINE__, a, ##__VA_ARGS__).c_str()
template <typename... Args>
std::string _make_str(const std::string& filename, int line, const std::string& fmt, Args... args) {
const int size = std::snprintf(nullptr, 0, fmt.c_str(), args...);
std::vector<char> buf(size + 1);
std::snprintf(buf.data(), buf.size(), fmt.c_str(), args...);
std::stringstream ss;
ss << "[" << filename << ":" << line << "] " << std::string(buf.begin(), buf.end());
return ss.str();
}