| 46 | } |
| 47 | |
| 48 | void _MMKVLogWithLevel(MMKVLogLevel level, const char *filename, const char *func, int line, const char *format, ...) { |
| 49 | if (level >= g_currentLogLevel) { |
| 50 | string message; |
| 51 | char buffer[16]; |
| 52 | |
| 53 | va_list args; |
| 54 | va_start(args, format); |
| 55 | auto length = std::vsnprintf(buffer, sizeof(buffer), format, args); |
| 56 | va_end(args); |
| 57 | |
| 58 | if (length < 0) { // something wrong |
| 59 | message = {}; |
| 60 | } else if (length < sizeof(buffer)) { |
| 61 | message = string(buffer, static_cast<unsigned long>(length)); |
| 62 | } else { |
| 63 | message.resize(static_cast<unsigned long>(length), '\0'); |
| 64 | va_start(args, format); |
| 65 | std::vsnprintf(const_cast<char *>(message.data()), static_cast<size_t>(length) + 1, format, args); |
| 66 | va_end(args); |
| 67 | } |
| 68 | |
| 69 | if (g_handler) { |
| 70 | g_handler->mmkvLog(level, filename, line, func, message); |
| 71 | } else { |
| 72 | auto desc = MMKVLogLevelDesc(level); |
| 73 | OH_LOG_Print(LOG_APP, desc, 0, APP_NAME, "<%{public}s:%{public}d::%{public}s> %{public}s", |
| 74 | filename, line, func, message.c_str()); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | # elif defined(MMKV_ANDROID) |
| 80 | # include <android/log.h> |
nothing calls this directly
no test coverage detected