diff options
-rw-r--r-- | common/nslog_log.hpp | 20 | ||||
-rw-r--r-- | common/nslog_log.mm | 24 | ||||
-rw-r--r-- | common/stderr_log.cpp | 20 | ||||
-rw-r--r-- | common/stderr_log.hpp | 20 | ||||
-rw-r--r-- | include/llmr/platform/event.hpp | 3 | ||||
m--------- | ios/mapbox-gl-cocoa | 0 | ||||
-rw-r--r-- | linux/main.cpp | 5 | ||||
-rw-r--r-- | macosx/llmr-app.gyp | 2 | ||||
-rw-r--r-- | macosx/main.mm | 7 | ||||
-rw-r--r-- | src/platform/event.cpp | 38 |
10 files changed, 121 insertions, 18 deletions
diff --git a/common/nslog_log.hpp b/common/nslog_log.hpp new file mode 100644 index 0000000000..d4ea6f6eaa --- /dev/null +++ b/common/nslog_log.hpp @@ -0,0 +1,20 @@ +#ifndef LLMR_COMMON_NSLOG_LOG +#define LLMR_COMMON_NSLOG_LOG + +#include <llmr/platform/log.hpp> + +namespace llmr { + +class NSLogBackend : public LogBackend { +public: + inline ~NSLogBackend() = default; + + void record(EventSeverity severity, Event event, const std::string &msg); + 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/common/nslog_log.mm b/common/nslog_log.mm new file mode 100644 index 0000000000..eed0810aee --- /dev/null +++ b/common/nslog_log.mm @@ -0,0 +1,24 @@ +#include "nslog_log.hpp" + +#import <Foundation/Foundation.h> + +namespace llmr { + +void NSLogBackend::record(EventSeverity severity, Event event, const std::string &msg) { + NSLog(@"[%s] %s: %@", stringifyEventSeverity(severity), stringifyEvent(event), + [[NSString alloc] initWithBytes:msg.data() + length:msg.size() + encoding:NSUTF8StringEncoding]); +} + +void NSLogBackend::record(EventSeverity severity, Event event, int64_t code) { + NSLog(@"[%s] %s: (%lld)", stringifyEventSeverity(severity), stringifyEvent(event), code); +} + +void NSLogBackend::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) { + NSLog(@"[%s] %s: (%lld) %@", stringifyEventSeverity(severity), stringifyEvent(event), code, + [[NSString alloc] initWithBytes:msg.data() + length:msg.size() + encoding:NSUTF8StringEncoding]); +} +} diff --git a/common/stderr_log.cpp b/common/stderr_log.cpp new file mode 100644 index 0000000000..b3b1fea333 --- /dev/null +++ b/common/stderr_log.cpp @@ -0,0 +1,20 @@ +#include "stderr_log.hpp" + +#include <iostream> + +namespace llmr { + +void StderrLogBackend::record(EventSeverity severity, Event event, const std::string &msg) { + std::cerr << "[" << severity << "] " << event << ": " << msg << std::endl; +} + +void StderrLogBackend::record(EventSeverity severity, Event event, int64_t code) { + std::cerr << "[" << severity << "] " << event << ": (" << code << ")" << std::endl; +} + +void StderrLogBackend::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) { + std::cerr << "[" << severity << "] " << event << ": (" << code << ") " << msg << std::endl; + +} + +} diff --git a/common/stderr_log.hpp b/common/stderr_log.hpp new file mode 100644 index 0000000000..32b6850cb7 --- /dev/null +++ b/common/stderr_log.hpp @@ -0,0 +1,20 @@ +#ifndef LLMR_COMMON_STDERR_LOG +#define LLMR_COMMON_STDERR_LOG + +#include <llmr/platform/log.hpp> + +namespace llmr { + +class StderrLogBackend : public LogBackend { +public: + inline ~StderrLogBackend() = default; + + void record(EventSeverity severity, Event event, const std::string &msg); + 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/llmr/platform/event.hpp b/include/llmr/platform/event.hpp index 2f5633c07f..930f79fac6 100644 --- a/include/llmr/platform/event.hpp +++ b/include/llmr/platform/event.hpp @@ -15,9 +15,11 @@ enum class EventSeverity : uint8_t { }; EventSeverity parseEventSeverity(const char *name); +const char *stringifyEventSeverity(EventSeverity eventSeverity); ::std::ostream& operator<<(::std::ostream& os, EventSeverity eventSeverity); enum class Event : uint8_t { + Setup, ParseStyle, ParseTile, Render, @@ -25,6 +27,7 @@ enum class Event : uint8_t { }; Event parseEvent(const char *name); +const char *stringifyEvent(Event event); ::std::ostream& operator<<(::std::ostream& os, Event event); constexpr EventSeverity enabledEventSeverities[] = { diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa -Subproject e16b737daaf9ecd2a02f7ccc61a590e9df8b205 +Subproject 9d403d2cefcd63797a3da2c67d4b653e287aeec diff --git a/linux/main.cpp b/linux/main.cpp index 889a246c29..11a21880f1 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -8,6 +8,7 @@ #include "../common/settings_json.hpp" #include "../common/glfw_view.hpp" +#include "../common/stderr_log.hpp" GLFWView *view = nullptr; @@ -22,6 +23,8 @@ void quit_handler(int) { } int main(int argc, char *argv[]) { + llmr::Log::Set<llmr::StderrLogBackend>(); + int fullscreen_flag = 0; const struct option long_options[] = { @@ -63,7 +66,7 @@ int main(int argc, char *argv[]) { // Set access token if present const char *token = getenv("MAPBOX_ACCESS_TOKEN"); if (token == nullptr) { - fprintf(stderr, "[WARNING] no access token set. mapbox.com tiles won't work.\n"); + llmr::Log::Warning(llmr::Event::Setup, "no access token set. mapbox.com tiles won't work."); } else { map.setAccessToken(std::string(token)); } diff --git a/macosx/llmr-app.gyp b/macosx/llmr-app.gyp index 02319da94b..139cb744c5 100644 --- a/macosx/llmr-app.gyp +++ b/macosx/llmr-app.gyp @@ -16,6 +16,8 @@ '../common/glfw_view.cpp', '../common/foundation_request.h', '../common/foundation_request.mm', + '../common/nslog_log.hpp', + '../common/nslog_log.mm', ], 'product_extension': 'app', 'mac_bundle': 1, diff --git a/macosx/main.mm b/macosx/main.mm index 3b01df04e6..f72476cde2 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -1,9 +1,12 @@ #include "../common/settings_nsuserdefaults.hpp" #include "../common/glfw_view.hpp" +#include "../common/nslog_log.hpp" #import <Foundation/Foundation.h> int main() { + llmr::Log::Set<llmr::NSLogBackend>(); + GLFWView view; llmr::Map map(view); @@ -16,7 +19,7 @@ int main() { // Set access token if present const char *token = getenv("MAPBOX_ACCESS_TOKEN"); if (token == nullptr) { - fprintf(stderr, "[WARNING] no access token set. mapbox.com tiles won't work.\n"); + llmr::Log::Warning(llmr::Event::Setup, "no access token set. mapbox.com tiles won't work."); } else { map.setAccessToken(std::string(token)); } @@ -28,8 +31,6 @@ int main() { error:nil]; map.setStyleJSON((std::string)[json cStringUsingEncoding:[NSString defaultCStringEncoding]]); - // fprintf(stderr, "lon: %f, lat: %f, zoom: %f, angle: %f, debug: %d\n", settings.l) - int ret = view.run(); // Save settings diff --git a/src/platform/event.cpp b/src/platform/event.cpp index 674bdbc8a8..8d55074234 100644 --- a/src/platform/event.cpp +++ b/src/platform/event.cpp @@ -13,18 +13,23 @@ EventSeverity parseEventSeverity(const char *name) { return EventSeverity(-1); } -::std::ostream& operator<<(::std::ostream& os, EventSeverity eventSeverity) { +const char *stringifyEventSeverity(EventSeverity eventSeverity) { switch (eventSeverity) { - case EventSeverity::Debug: return os << "DEBUG"; - case EventSeverity::Info: return os << "INFO"; - case EventSeverity::Test: return os << "TEST"; - case EventSeverity::Warning: return os << "WARNING"; - case EventSeverity::Error: return os << "ERROR"; - default: return os << "UNKNOWN"; + case EventSeverity::Debug: return "DEBUG"; + case EventSeverity::Info: return "INFO"; + case EventSeverity::Test: return "TEST"; + case EventSeverity::Warning: return "WARNING"; + case EventSeverity::Error: return "ERROR"; + default: return "UNKNOWN"; } } +::std::ostream& operator<<(::std::ostream& os, EventSeverity eventSeverity) { + return os << stringifyEventSeverity(eventSeverity); +} + Event parseEvent(const char *name) { + if (strcmp(name, "Setup") == 0) return Event::Setup; if (strcmp(name, "ParseStyle") == 0) return Event::ParseStyle; if (strcmp(name, "ParseTile") == 0) return Event::ParseTile; if (strcmp(name, "Render") == 0) return Event::Render; @@ -32,15 +37,20 @@ Event parseEvent(const char *name) { return Event(-1); } -::std::ostream& operator<<(::std::ostream& os, Event event) { - switch (event) { - case Event::ParseStyle: return os << "ParseStyle"; - case Event::ParseTile: return os << "ParseTile"; - case Event::Render: return os << "Render"; - case Event::HttpRequest: return os << "HttpRequest"; - default: return os << "Unknown"; +const char *stringifyEvent(Event event) { + switch (event) { + case Event::Setup: return "Setup"; + case Event::ParseStyle: return "ParseStyle"; + case Event::ParseTile: return "ParseTile"; + case Event::Render: return "Render"; + case Event::HttpRequest: return "HttpRequest"; + default: return "Unknown"; } } +::std::ostream& operator<<(::std::ostream& os, Event event) { + return os << stringifyEvent(event); +} + } |