Added code to output libSession logs
parent
d7f697572e
commit
3a339b15f9
@ -0,0 +1,48 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include <android/log.h>
|
||||||
|
#include <string_view>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
#include "session/logging.hpp"
|
||||||
|
#include "session/log_level.h"
|
||||||
|
|
||||||
|
#define LOG_TAG "LibSession"
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL
|
||||||
|
Java_network_loki_messenger_libsession_1util_util_Logger_initLogger(JNIEnv* env, jclass clazz) {
|
||||||
|
session::add_logger([](std::string_view msg, std::string_view category, session::LogLevel level) {
|
||||||
|
android_LogPriority prio = ANDROID_LOG_VERBOSE;
|
||||||
|
|
||||||
|
switch (level.level) {
|
||||||
|
case LOG_LEVEL_TRACE:
|
||||||
|
prio = ANDROID_LOG_VERBOSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOG_LEVEL_DEBUG:
|
||||||
|
prio = ANDROID_LOG_DEBUG;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOG_LEVEL_INFO:
|
||||||
|
prio = ANDROID_LOG_INFO;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOG_LEVEL_WARN:
|
||||||
|
prio = ANDROID_LOG_WARN;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOG_LEVEL_ERROR:
|
||||||
|
case LOG_LEVEL_CRITICAL:
|
||||||
|
prio = ANDROID_LOG_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
prio = ANDROID_LOG_INFO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
__android_log_print(prio, LOG_TAG, "%.*s [%.*s]",
|
||||||
|
static_cast<int>(msg.size()), msg.data(),
|
||||||
|
static_cast<int>(category.size()), category.data());
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef SESSION_ANDROID_LOGGING_H
|
||||||
|
#define SESSION_ANDROID_LOGGING_H
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Declaration of the JNI function following the JNI naming convention.
|
||||||
|
JNIEXPORT void JNICALL Java_network_loki_messenger_libsession_1util_util_Logger_initLogger(JNIEnv* env, jclass clazz);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //SESSION_ANDROID_LOGGING_H
|
@ -0,0 +1,11 @@
|
|||||||
|
package network.loki.messenger.libsession_util.util
|
||||||
|
|
||||||
|
object Logger {
|
||||||
|
|
||||||
|
init {
|
||||||
|
System.loadLibrary("session_util")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
external fun initLogger()
|
||||||
|
}
|
Loading…
Reference in New Issue