allow formatted messages
This commit is contained in:
@@ -19,7 +19,9 @@ const char *stringifyEventSeverity(EventSeverity eventSeverity);
|
||||
::std::ostream& operator<<(::std::ostream& os, EventSeverity eventSeverity);
|
||||
|
||||
enum class Event : uint8_t {
|
||||
General,
|
||||
Setup,
|
||||
Shader,
|
||||
ParseStyle,
|
||||
ParseTile,
|
||||
Render,
|
||||
@@ -30,25 +32,30 @@ Event parseEvent(const char *name);
|
||||
const char *stringifyEvent(Event event);
|
||||
::std::ostream& operator<<(::std::ostream& os, Event event);
|
||||
|
||||
constexpr EventSeverity enabledEventSeverities[] = {
|
||||
#if DEBUG
|
||||
EventSeverity::Debug,
|
||||
#endif
|
||||
struct EventPermutation {
|
||||
const EventSeverity severity;
|
||||
const Event event;
|
||||
|
||||
#if TESTING
|
||||
EventSeverity::Test,
|
||||
#endif
|
||||
|
||||
EventSeverity::Info,
|
||||
EventSeverity::Warning,
|
||||
EventSeverity::Error,
|
||||
constexpr bool operator==(const EventPermutation &rhs) const {
|
||||
return severity == rhs.severity && event == rhs.event;
|
||||
}
|
||||
};
|
||||
|
||||
/* enabled event classes */
|
||||
constexpr Event enabledEvents[] = {
|
||||
Event::ParseStyle,
|
||||
Event::ParseTile,
|
||||
Event::HttpRequest,
|
||||
constexpr EventSeverity disabledEventSeverities[] = {
|
||||
#if !DEBUG
|
||||
EventSeverity::Debug,
|
||||
#endif
|
||||
#if !TESTING
|
||||
EventSeverity::Test,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
constexpr Event disabledEvents[] = {
|
||||
};
|
||||
|
||||
constexpr EventPermutation disabledEventPermutations[] = {
|
||||
{ EventSeverity::Debug, Event::Shader }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class LogBackend {
|
||||
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;
|
||||
};
|
||||
@@ -46,8 +47,9 @@ public:
|
||||
|
||||
template <typename ...Args>
|
||||
static inline void Record(EventSeverity severity, Event event, Args&& ...args) {
|
||||
if (includes(severity, enabledEventSeverities) &&
|
||||
includes(event, enabledEvents)) {
|
||||
if (!includes(severity, disabledEventSeverities) &&
|
||||
!includes(event, disabledEvents) &&
|
||||
!includes({ severity, event }, disabledEventPermutations)) {
|
||||
if (Backend) {
|
||||
Backend->record(severity, event, ::std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef LLMR_UTIL_TIMER
|
||||
#define LLMR_UTIL_TIMER
|
||||
|
||||
#include <llmr/platform/event.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace llmr {
|
||||
@@ -9,24 +11,29 @@ namespace util {
|
||||
#ifndef DISABLE_TIMER
|
||||
class timer {
|
||||
public:
|
||||
timer();
|
||||
timer(const std::string &name);
|
||||
timer(Event event = Event::General);
|
||||
timer(EventSeverity severity, Event event = Event::General);
|
||||
timer(const std::string &name, Event event = Event::General);
|
||||
timer(const std::string &name, EventSeverity severity, Event event = Event::General);
|
||||
void report(const std::string &name);
|
||||
~timer();
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
EventSeverity severity = EventSeverity::Debug;
|
||||
Event event = Event::General;
|
||||
uint64_t start;
|
||||
};
|
||||
#else
|
||||
class timer {
|
||||
inline timer() {}
|
||||
inline timer(const std::string &name) {}
|
||||
inline void report (const std::string &name) {}
|
||||
inline timer(Event event = Event::General);
|
||||
inline timer(EventSeverity severity, Event event = Event::General);
|
||||
inline timer(const std::string &name, Event event = Event::General);
|
||||
inline timer(const std::string &name, EventSeverity severity, Event event = Event::General);
|
||||
inline void report(const std::string &name) {}
|
||||
inline ~timer() {}
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user