| 68 | } |
| 69 | |
| 70 | void _MMKVLogWithLevel(const char *filename, const char *func, int line, const char *format, ...) { |
| 71 | string message; |
| 72 | char buffer[16]; |
| 73 | |
| 74 | va_list args; |
| 75 | va_start(args, format); |
| 76 | auto length = std::vsnprintf(buffer, sizeof(buffer), format, args); |
| 77 | va_end(args); |
| 78 | |
| 79 | if (length < 0) { // something wrong |
| 80 | message = {}; |
| 81 | } else if (length < sizeof(buffer)) { |
| 82 | message = string(buffer, static_cast<unsigned long>(length)); |
| 83 | } else { |
| 84 | message.resize(static_cast<unsigned long>(length), '\0'); |
| 85 | va_start(args, format); |
| 86 | std::vsnprintf(const_cast<char *>(message.data()), static_cast<size_t>(length) + 1, format, args); |
| 87 | va_end(args); |
| 88 | } |
| 89 | |
| 90 | OH_LOG_Print(LOG_APP, LOG_INFO, 0, "mmkvdemo", "<%{public}s:%{public}d::%{public}s> %{public}s", |
| 91 | filename, line, func, message.c_str()); |
| 92 | } |
| 93 | |
| 94 | #define MMKVLog(format, ...) \ |
| 95 | _MMKVLogWithLevel(__FILE_NAME__, __func__, __LINE__, format, ##__VA_ARGS__) |
nothing calls this directly
no outgoing calls
no test coverage detected