diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-07-11 14:34:17 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-07-11 14:34:17 -0700 |
commit | 7ffe4a7858bc5d071b87612bdaa19d8eaf29045c (patch) | |
tree | 701750687b9331dcd290d9831ad8b62be9a97cae /common | |
parent | f3c55eba9da59042a96e683f841060674519520b (diff) | |
download | qtlocation-mapboxgl-7ffe4a7858bc5d071b87612bdaa19d8eaf29045c.tar.gz |
add nslog and stderr log backends
Diffstat (limited to 'common')
-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 |
4 files changed, 84 insertions, 0 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 |