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).
65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
#ifndef MBGL_PLATFORM_LOG
|
|
#define MBGL_PLATFORM_LOG
|
|
|
|
#include <mbgl/platform/event.hpp>
|
|
|
|
#include <mbgl/util/std.hpp>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace mbgl {
|
|
|
|
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) {
|
|
return i < N && (l[i] == e || includes(e, l, i + 1));
|
|
}
|
|
|
|
public:
|
|
template <typename ...Args>
|
|
static inline void Debug(Event event, Args&& ...args) {
|
|
Record(EventSeverity::Debug, event, ::std::forward<Args>(args)...);
|
|
}
|
|
|
|
template <typename ...Args>
|
|
static inline void Info(Event event, Args&& ...args) {
|
|
Record(EventSeverity::Info, event, ::std::forward<Args>(args)...);
|
|
}
|
|
|
|
template <typename ...Args>
|
|
static inline void Warning(Event event, Args&& ...args) {
|
|
Record(EventSeverity::Warning, event, ::std::forward<Args>(args)...);
|
|
}
|
|
|
|
template <typename ...Args>
|
|
static inline void Error(Event event, Args&& ...args) {
|
|
Record(EventSeverity::Error, event, ::std::forward<Args>(args)...);
|
|
}
|
|
|
|
template <typename ...Args>
|
|
static inline void Record(EventSeverity severity, Event event, Args&& ...args) {
|
|
if (!includes(severity, disabledEventSeverities) &&
|
|
!includes(event, disabledEvents) &&
|
|
!includes({ severity, event }, disabledEventPermutations)) {
|
|
record(severity, event, ::std::forward<Args>(args)...);
|
|
}
|
|
}
|
|
|
|
private:
|
|
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);
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|