summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2015-03-12 14:18:25 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2015-03-12 14:18:25 +0200
commit2b6afe6a549284a862d0231653d2183d57a5b496 (patch)
tree715182b2fc50edd793b6a945950b68c7b135ec8d /include
parent4e8036311d434db9bb1bd41b65bd39e2891e17d0 (diff)
parent79f3149d9d973a31bcc5cf3ba1dbe77d90884ace (diff)
downloadqtlocation-mapboxgl-2b6afe6a549284a862d0231653d2183d57a5b496.tar.gz
Merge pull request #972 from mapbox/log_cleanup
Refactoring of the log system
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/platform/android/log_android.hpp24
-rw-r--r--include/mbgl/platform/darwin/log_nslog.hpp21
-rw-r--r--include/mbgl/platform/default/log_stderr.hpp21
-rw-r--r--include/mbgl/platform/log.hpp39
4 files changed, 21 insertions, 84 deletions
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 d40f963036..0000000000
--- a/include/mbgl/platform/darwin/log_nslog.hpp
+++ /dev/null
@@ -1,21 +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, 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/default/log_stderr.hpp b/include/mbgl/platform/default/log_stderr.hpp
deleted file mode 100644
index 45f76f0d1a..0000000000
--- a/include/mbgl/platform/default/log_stderr.hpp
+++ /dev/null
@@ -1,21 +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, 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/log.hpp b/include/mbgl/platform/log.hpp
index 8b58921bbe..de7f131714 100644
--- a/include/mbgl/platform/log.hpp
+++ b/include/mbgl/platform/log.hpp
@@ -10,16 +10,19 @@
namespace mbgl {
-class LogBackend {
+class Log {
public:
- virtual inline ~LogBackend() = default;
- virtual void record(EventSeverity severity, Event event, const std::string &msg) = 0;
- virtual void record(EventSeverity severity, Event event, const char* format, ...) = 0;
- virtual void record(EventSeverity severity, Event event, int64_t code) = 0;
- virtual void record(EventSeverity severity, Event event, int64_t code, const std::string &msg) = 0;
-};
+ class Observer {
+ public:
+ virtual ~Observer() = default;
+
+ // When an observer is set, this function will be called for every log
+ // message. Returning true will consume the message.
+ virtual bool onRecord(EventSeverity severity, Event event, int64_t code, const std::string &msg) = 0;
+ };
+
+ static void setObserver(std::unique_ptr<Observer> Observer);
-class Log {
private:
template <typename T, size_t N>
constexpr static bool includes(const T e, const T (&l)[N], const size_t i = 0) {
@@ -52,20 +55,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);
};
}