Simplify the logging mechanism

Move the implementation of the more specialized methods to the base
class and let the platform implement only the most generic method that
takes all the possible arguments.

These specialized methods will then map to the generic implementation
that must be provided by the platforms we support.
This commit is contained in:
Thiago Marcos P. Santos
2015-03-09 15:42:11 +02:00
committed by Thiago Marcos P. Santos
parent ba9d242069
commit 2948e7d121
7 changed files with 26 additions and 81 deletions

View File

@@ -1,7 +1,5 @@
#include <mbgl/platform/android/log_android.hpp>
#include <iostream>
#include <cstdarg>
#define __STDC_FORMAT_MACROS // NDK bug workaround: https://code.google.com/p/android/issues/detail?id=72349
#include <cinttypes>
@@ -28,30 +26,6 @@ int AndroidLogBackend::severityToPriority(EventSeverity severity) {
}
}
void AndroidLogBackend::record(EventSeverity severity, Event event, const std::string &msg) {
__android_log_print(severityToPriority(severity), EventClass(event).c_str(), "%s", msg.c_str());
}
void AndroidLogBackend::record(EventSeverity severity, Event event, const char* format, ...) {
va_list args;
va_start(args, format);
const int len = vsnprintf(nullptr, 0, format, args) + 1;
char* buf = new char[len];
vsnprintf(buf, len, format, args);
va_end(args);
__android_log_print(severityToPriority(severity), EventClass(event).c_str(), "%s", buf);
delete buf;
buf = nullptr;
}
void AndroidLogBackend::record(EventSeverity severity, Event event, int64_t code) {
__android_log_print(severityToPriority(severity), EventClass(event).c_str(), "(%" PRId64 ")", code);
}
void AndroidLogBackend::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) {
__android_log_print(severityToPriority(severity), EventClass(event).c_str(), "(%" PRId64 ") %s", code, msg.c_str());
}