To make it easier to debug, add the Environment ID and the Thread name
to the log messages. For instance log messages from the TileParser will look like:
[WARNING] {0}{TileWorker_15/18653/9486}[ParseTile]: some relevant warning message
| | | |
| | | +-> Component
| | +--------------------> Thread name
| +----------------------------------> Environment ID
+------------------------------------------> Severity level
Log messages that are not inside an Environment::Scope will work
normally and will look like:
[WARNING] [JNI]: some relevant warning message
Fixes #882.
35 lines
662 B
C++
35 lines
662 B
C++
#include <mbgl/platform/log.hpp>
|
|
|
|
#include <android/log.h>
|
|
|
|
namespace mbgl {
|
|
|
|
namespace {
|
|
|
|
int severityToPriority(EventSeverity severity) {
|
|
switch(severity) {
|
|
case EventSeverity::Debug:
|
|
return ANDROID_LOG_DEBUG;
|
|
|
|
case EventSeverity::Info:
|
|
return ANDROID_LOG_INFO;
|
|
|
|
case EventSeverity::Warning:
|
|
return ANDROID_LOG_WARN;
|
|
|
|
case EventSeverity::Error:
|
|
return ANDROID_LOG_ERROR;
|
|
|
|
default:
|
|
return ANDROID_LOG_VERBOSE;
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void Log::platformRecord(EventSeverity severity, const std::string &msg) {
|
|
__android_log_print(severityToPriority(severity), "mbgl", "%s", msg.c_str());
|
|
}
|
|
|
|
}
|