diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2015-03-09 16:15:18 +0200 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-03-12 13:28:41 +0200 |
commit | 51bc265db341f1d98b4fd46be80241771f854eb5 (patch) | |
tree | dc77abcdc9b423b59da94d32ae2afb0f57fb6f8d /include/mbgl | |
parent | 2948e7d121343359b817d2fb0eb383e257ab84c8 (diff) | |
download | qtlocation-mapboxgl-51bc265db341f1d98b4fd46be80241771f854eb5.tar.gz |
Make the logging system static
No initialization is needed anymore and we can use the logging functions
safely at any point of the code (threading is not handled though, so you
might get multiplexed messages if you log from two threads
simultaneously).
Diffstat (limited to 'include/mbgl')
-rw-r--r-- | include/mbgl/platform/android/log_android.hpp | 24 | ||||
-rw-r--r-- | include/mbgl/platform/darwin/log_nslog.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/platform/default/log_stderr.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/platform/log.hpp | 31 |
4 files changed, 10 insertions, 81 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 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); }; } |