summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/cpp/jni.cpp3
-rw-r--r--bin/render.cpp14
-rw-r--r--include/mbgl/platform/android/log_android.hpp24
-rw-r--r--include/mbgl/platform/darwin/log_nslog.hpp18
-rw-r--r--include/mbgl/platform/default/log_stderr.hpp18
-rw-r--r--include/mbgl/platform/log.hpp31
-rw-r--r--linux/main.cpp4
-rw-r--r--macosx/main.mm4
-rw-r--r--platform/android/log_android.cpp10
-rw-r--r--platform/darwin/log_nslog.mm6
-rw-r--r--platform/default/log_stderr.cpp4
-rw-r--r--platform/ios/MGLMapView.mm6
-rw-r--r--src/mbgl/platform/log.cpp12
13 files changed, 33 insertions, 121 deletions
diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp
index 1163c33b57..62e153e9b9 100644
--- a/android/cpp/jni.cpp
+++ b/android/cpp/jni.cpp
@@ -15,7 +15,6 @@
#include <mbgl/android/jni.hpp>
#include <mbgl/android/native_map_view.hpp>
#include <mbgl/map/map.hpp>
-#include <mbgl/platform/android/log_android.hpp>
#include <mbgl/platform/event.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/storage/network_status.hpp>
@@ -827,8 +826,6 @@ jobject JNICALL nativeLatLngForPixel(JNIEnv *env, jobject obj, jlong nativeMapVi
extern "C" {
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
- mbgl::Log::Set<mbgl::AndroidLogBackend>();
-
mbgl::Log::Debug(mbgl::Event::JNI, "JNI_OnLoad");
JNIEnv *env = nullptr;
diff --git a/bin/render.cpp b/bin/render.cpp
index 71981b9d96..01f6929092 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -5,15 +5,10 @@
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/headless_display.hpp>
+#include <mbgl/platform/log.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/default/sqlite_cache.hpp>
-#if __APPLE__
-#include <mbgl/platform/darwin/log_nslog.hpp>
-#else
-#include <mbgl/platform/default/log_stderr.hpp>
-#endif
-
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
@@ -71,13 +66,6 @@ int main(int argc, char *argv[]) {
using namespace mbgl;
-
-#if __APPLE__
- Log::Set<NSLogBackend>();
-#else
- Log::Set<StderrLogBackend>();
-#endif
-
mbgl::SQLiteCache cache(cache_file);
mbgl::DefaultFileSource fileSource(&cache);
diff --git a/include/mbgl/platform/android/log_android.hpp b/include/mbgl/platform/android/log_android.hpp
deleted file mode 100644
index 94d90a9b36..0000000000
--- a/include/mbgl/platform/android/log_android.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef MBGL_PLATFORM_ANDROID_LOG_ANDROID
-#define MBGL_PLATFORM_ANDROID_LOG_ANDROID
-
-#include <mbgl/platform/log.hpp>
-
-namespace mbgl {
-
-class AndroidLogBackend : public LogBackend {
-private:
- int severityToPriority(EventSeverity severity);
-
-public:
- inline ~AndroidLogBackend() = default;
-
- void record(EventSeverity severity, Event event, const std::string &msg);
- void record(EventSeverity severity, Event event, const char* format, ...);
- void record(EventSeverity severity, Event event, int64_t code);
- void record(EventSeverity severity, Event event, int64_t code, const std::string &msg);
-};
-
-
-}
-
-#endif
diff --git a/include/mbgl/platform/darwin/log_nslog.hpp b/include/mbgl/platform/darwin/log_nslog.hpp
deleted file mode 100644
index 5b2ed04114..0000000000
--- a/include/mbgl/platform/darwin/log_nslog.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef MBGL_COMMON_NSLOG_LOG
-#define MBGL_COMMON_NSLOG_LOG
-
-#include <mbgl/platform/log.hpp>
-
-namespace mbgl {
-
-class NSLogBackend : public LogBackend {
-public:
- inline ~NSLogBackend() = default;
-
- void record(EventSeverity severity, Event event, int64_t code, const std::string &msg);
-};
-
-
-}
-
-#endif
diff --git a/include/mbgl/platform/default/log_stderr.hpp b/include/mbgl/platform/default/log_stderr.hpp
deleted file mode 100644
index e07357593d..0000000000
--- a/include/mbgl/platform/default/log_stderr.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef MBGL_COMMON_STDERR_LOG
-#define MBGL_COMMON_STDERR_LOG
-
-#include <mbgl/platform/log.hpp>
-
-namespace mbgl {
-
-class StderrLogBackend : public LogBackend {
-public:
- inline ~StderrLogBackend() = default;
-
- void record(EventSeverity severity, Event event, int64_t code, const std::string &msg) override;
-};
-
-
-}
-
-#endif
diff --git a/include/mbgl/platform/log.hpp b/include/mbgl/platform/log.hpp
index e5431a07cb..e6b8f17b65 100644
--- a/include/mbgl/platform/log.hpp
+++ b/include/mbgl/platform/log.hpp
@@ -10,17 +10,6 @@
namespace mbgl {
-class LogBackend {
-public:
- virtual inline ~LogBackend() = default;
-
- void record(EventSeverity severity, Event event, const std::string &msg);
- void record(EventSeverity severity, Event event, const char* format, ...);
- void record(EventSeverity severity, Event event, int64_t code);
-
- virtual void record(EventSeverity severity, Event event, int64_t code, const std::string &msg) = 0;
-};
-
class Log {
private:
template <typename T, size_t N>
@@ -54,20 +43,20 @@ public:
if (!includes(severity, disabledEventSeverities) &&
!includes(event, disabledEvents) &&
!includes({ severity, event }, disabledEventPermutations)) {
- if (Backend) {
- Backend->record(severity, event, ::std::forward<Args>(args)...);
- }
+ record(severity, event, ::std::forward<Args>(args)...);
}
}
- template<typename T, typename ...Args>
- static inline const T &Set(Args&& ...args) {
- Backend = util::make_unique<T>(::std::forward<Args>(args)...);
- return *reinterpret_cast<T *>(Backend.get());
- }
-
private:
- static std::unique_ptr<LogBackend> Backend;
+ static void record(EventSeverity severity, Event event, const std::string &msg);
+ static void record(EventSeverity severity, Event event, const char* format, ...);
+ static void record(EventSeverity severity, Event event, int64_t code);
+ static void record(EventSeverity severity, Event event, int64_t code, const std::string &msg);
+
+ // This method is the data sink that must be implemented by each platform we
+ // support. It should ideally output the error message in a human readable
+ // format to the developer.
+ static void platformRecord(EventSeverity severity, Event event, int64_t code, const std::string &msg);
};
}
diff --git a/linux/main.cpp b/linux/main.cpp
index 6688905ea9..6a2be43d7c 100644
--- a/linux/main.cpp
+++ b/linux/main.cpp
@@ -1,9 +1,9 @@
#include <mbgl/mbgl.hpp>
#include <mbgl/util/uv.hpp>
+#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/default/settings_json.hpp>
#include <mbgl/platform/default/glfw_view.hpp>
-#include <mbgl/platform/default/log_stderr.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/default/sqlite_cache.hpp>
@@ -26,8 +26,6 @@ void quit_handler(int) {
}
int main(int argc, char *argv[]) {
- mbgl::Log::Set<mbgl::StderrLogBackend>();
-
int fullscreen_flag = 0;
std::string style;
diff --git a/macosx/main.mm b/macosx/main.mm
index f59fbda6a8..087544f7c4 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -1,6 +1,6 @@
+#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/darwin/settings_nsuserdefaults.hpp>
-#include <mbgl/platform/darwin/log_nslog.hpp>
#include <mbgl/platform/darwin/Reachability.h>
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/storage/default_file_source.hpp>
@@ -101,8 +101,6 @@ const std::string &defaultCacheDatabase() {
}
int main() {
- mbgl::Log::Set<mbgl::NSLogBackend>();
-
GLFWView view;
mbgl::SQLiteCache cache(defaultCacheDatabase());
diff --git a/platform/android/log_android.cpp b/platform/android/log_android.cpp
index e1bec3e0cb..9de8232bac 100644
--- a/platform/android/log_android.cpp
+++ b/platform/android/log_android.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/platform/android/log_android.hpp>
+#include <mbgl/platform/log.hpp>
#define __STDC_FORMAT_MACROS // NDK bug workaround: https://code.google.com/p/android/issues/detail?id=72349
#include <cinttypes>
@@ -7,7 +7,9 @@
namespace mbgl {
-int AndroidLogBackend::severityToPriority(EventSeverity severity) {
+namespace {
+
+int severityToPriority(EventSeverity severity) {
switch(severity) {
case EventSeverity::Debug:
return ANDROID_LOG_DEBUG;
@@ -26,7 +28,9 @@ int AndroidLogBackend::severityToPriority(EventSeverity severity) {
}
}
-void AndroidLogBackend::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) {
+} // namespace
+
+void Log::platformRecord(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());
}
diff --git a/platform/darwin/log_nslog.mm b/platform/darwin/log_nslog.mm
index edcf41ebb2..5d53ed812f 100644
--- a/platform/darwin/log_nslog.mm
+++ b/platform/darwin/log_nslog.mm
@@ -1,11 +1,11 @@
-#include <mbgl/platform/darwin/log_nslog.hpp>
+#include <mbgl/platform/log.hpp>
#import <Foundation/Foundation.h>
namespace mbgl {
-void NSLogBackend::record(EventSeverity severity, Event event, int64_t code,
- const std::string &msg) {
+void Log::platformRecord(EventSeverity severity, Event event, int64_t code,
+ const std::string &msg) {
NSString *message =
[[NSString alloc] initWithBytes:msg.data() length:msg.size() encoding:NSUTF8StringEncoding];
NSLog(@"[%s] %s: (%lld) %@", EventSeverityClass(severity).c_str(), EventClass(event).c_str(),
diff --git a/platform/default/log_stderr.cpp b/platform/default/log_stderr.cpp
index 891bfd57f8..3305176d96 100644
--- a/platform/default/log_stderr.cpp
+++ b/platform/default/log_stderr.cpp
@@ -1,10 +1,10 @@
-#include <mbgl/platform/default/log_stderr.hpp>
+#include <mbgl/platform/log.hpp>
#include <iostream>
namespace mbgl {
-void StderrLogBackend::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) {
+void Log::platformRecord(EventSeverity severity, Event event, int64_t code, const std::string &msg) {
std::cerr << "[" << severity << "] " << event << ": (" << code << ") " << msg << std::endl;
}
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 1ab1afcbba..f60d3a05ff 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -1,6 +1,6 @@
#import "MGLMapView.h"
-#import <mbgl/platform/darwin/log_nslog.hpp>
+#import <mbgl/platform/log.hpp>
#import <mbgl/platform/gl.hpp>
#import <GLKit/GLKit.h>
@@ -181,10 +181,6 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (BOOL)commonInit
{
- // set logging backend
- //
- mbgl::Log::Set<mbgl::NSLogBackend>();
-
// create context
//
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
diff --git a/src/mbgl/platform/log.cpp b/src/mbgl/platform/log.cpp
index 71463dc2f9..4bbff8da5d 100644
--- a/src/mbgl/platform/log.cpp
+++ b/src/mbgl/platform/log.cpp
@@ -4,13 +4,11 @@
namespace mbgl {
-std::unique_ptr<LogBackend> Log::Backend;
-
-void LogBackend::record(EventSeverity severity, Event event, const std::string &msg) {
+void Log::record(EventSeverity severity, Event event, const std::string &msg) {
record(severity, event, -1, msg);
}
-void LogBackend::record(EventSeverity severity, Event event, const char* format, ...) {
+void Log::record(EventSeverity severity, Event event, const char* format, ...) {
va_list args;
va_start(args, format);
char msg[4096];
@@ -20,8 +18,12 @@ void LogBackend::record(EventSeverity severity, Event event, const char* format,
record(severity, event, -1, msg);
}
-void LogBackend::record(EventSeverity severity, Event event, int64_t code) {
+void Log::record(EventSeverity severity, Event event, int64_t code) {
record(severity, event, code, std::string());
}
+void Log::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) {
+ platformRecord(severity, event, code, msg);
+}
+
}