summaryrefslogtreecommitdiff
path: root/platform/android/src/logging_android.cpp
blob: 786bb39c520d980d384617d83196202a5fd4e8f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <mbgl/util/logging.hpp>

#include <android/log.h>
#include "timber.hpp"
#include "attach_env.hpp"

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());
    if(severity == EventSeverity::Error) {
        auto env{ android::AttachEnv() };
        android::Timber::logError(*env, jni::Make<jni::String>(*env, msg.c_str()));
    }
}
}