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).
This commit is contained in:
Thiago Marcos P. Santos
2015-03-09 16:15:18 +02:00
committed by Thiago Marcos P. Santos
parent 2948e7d121
commit 51bc265db3
13 changed files with 33 additions and 121 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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);
};
}