summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-07-11 16:25:20 -0700
committerKonstantin Käfer <mail@kkaefer.com>2014-07-11 16:25:20 -0700
commitfbec72cd47a30788d1d5cf1df540c8f5bcf5613d (patch)
treeb4f387f4d7a7094f77e0863da528867019a21e62 /common
parent2dc9133006e5cc71c83d9e03d560b79de4f7a9fb (diff)
downloadqtlocation-mapboxgl-fbec72cd47a30788d1d5cf1df540c8f5bcf5613d.tar.gz
allow formatted messages
Diffstat (limited to 'common')
-rw-r--r--common/nslog_log.hpp1
-rw-r--r--common/nslog_log.mm13
-rw-r--r--common/stderr_log.cpp9
-rw-r--r--common/stderr_log.hpp1
4 files changed, 24 insertions, 0 deletions
diff --git a/common/nslog_log.hpp b/common/nslog_log.hpp
index d4ea6f6eaa..9f2f3aee7b 100644
--- a/common/nslog_log.hpp
+++ b/common/nslog_log.hpp
@@ -10,6 +10,7 @@ public:
inline ~NSLogBackend() = 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);
};
diff --git a/common/nslog_log.mm b/common/nslog_log.mm
index eed0810aee..ad685ea8dc 100644
--- a/common/nslog_log.mm
+++ b/common/nslog_log.mm
@@ -11,6 +11,19 @@ void NSLogBackend::record(EventSeverity severity, Event event, const std::string
encoding:NSUTF8StringEncoding]);
}
+
+void NSLogBackend::record(EventSeverity severity, Event event, const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ const int len = vsnprintf(NULL, 0, format, args);
+ va_end(args);
+ std::unique_ptr<char[]> buffer(new char[len + 1]);
+ va_start(args, format);
+ vsnprintf(buffer.get(), len + 1, format, args);
+ va_end(args);
+ NSLog(@"[%s] %s: %s", stringifyEventSeverity(severity), stringifyEvent(event), buffer.get());
+}
+
void NSLogBackend::record(EventSeverity severity, Event event, int64_t code) {
NSLog(@"[%s] %s: (%lld)", stringifyEventSeverity(severity), stringifyEvent(event), code);
}
diff --git a/common/stderr_log.cpp b/common/stderr_log.cpp
index b3b1fea333..18ad9b3f10 100644
--- a/common/stderr_log.cpp
+++ b/common/stderr_log.cpp
@@ -8,6 +8,15 @@ void StderrLogBackend::record(EventSeverity severity, Event event, const std::st
std::cerr << "[" << severity << "] " << event << ": " << msg << std::endl;
}
+void StderrLogBackend::record(EventSeverity severity, Event event, const char* format, ...) {
+ std::cerr << "[" << severity << "] " << event << ": ";
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+ std::cerr << std::endl;
+}
+
void StderrLogBackend::record(EventSeverity severity, Event event, int64_t code) {
std::cerr << "[" << severity << "] " << event << ": (" << code << ")" << std::endl;
}
diff --git a/common/stderr_log.hpp b/common/stderr_log.hpp
index 32b6850cb7..e2492d3af5 100644
--- a/common/stderr_log.hpp
+++ b/common/stderr_log.hpp
@@ -10,6 +10,7 @@ public:
inline ~StderrLogBackend() = 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);
};