Commit 9ec957a6 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added a better Java logger than the one in mediastreamer2 for Android apps

parent 99b1fb8d
......@@ -24,7 +24,7 @@ import org.linphone.core.Core;
import org.linphone.core.tools.DozeReceiver;
import org.linphone.core.tools.NetworkManager;
import org.linphone.core.tools.NetworkManagerAbove21;
import org.linphone.mediastream.Log;
import org.linphone.core.tools.Log;
import org.linphone.mediastream.MediastreamerAndroidContext;
import org.linphone.mediastream.Version;
......
......@@ -4,7 +4,7 @@ package org.linphone.core.tools;
import android.os.Build;
import org.linphone.core.Core;
import org.linphone.mediastream.Log;
import org.linphone.core.tools.Log;
/**
* Created by brieucviel on 09/12/2016.
......
/*
Log.java
Copyright (C) 2019 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.core.tools;
public final class Log {
private static Log logger;
private static String domain = "linphone-android";
private static Log instance() {
if (logger == null) {
logger = new Log();
logger.setLogDomain(domain);
}
return logger;
}
private Log () { }
private native void setDomain(String logDomain);
public static void setLogDomain(String logDomain) {
Log.instance().setDomain(logDomain);
Log.domain = logDomain;
}
private native void d(String domain, String msg);
public static void d(Object...objects) {
Log.instance().d(Log.domain, toString(objects));
}
private native void i(String domain, String msg);
public static void i(Object...objects) {
Log.instance().i(Log.domain, toString(objects));
}
private native void w(String domain, String msg);
public static void w(Object...objects) {
Log.instance().w(Log.domain, toString(objects));
}
private native void e(String domain, String msg);
public static void e(Object...objects) {
Log.instance().e(Log.domain, toString(objects));
}
private native void f(String domain, String msg);
public static void f(Object...objects) {
Log.instance().f(Log.domain, toString(objects));
}
private static String toString(Object...objects) {
StringBuilder sb = new StringBuilder();
for (Object o : objects) {
sb.append(o);
}
return sb.toString();
}
}
......@@ -32,7 +32,7 @@ import java.util.ArrayList;
import org.apache.commons.compress.compressors.bzip2.*;
import org.linphone.core.tools.OpenH264DownloadHelperListener;
import org.linphone.mediastream.Log;
import org.linphone.core.tools.Log;
/**
* @author Erwan Croze
......
......@@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <jni.h>
#include <cpu-features.h>
#include "bctoolbox/logging.h"
#include "belle-sip/object.h"
#include "mediastreamer2/mediastream.h"
#include "mediastreamer2/mscommon.h"
......@@ -196,6 +197,44 @@ JNIEXPORT void JNICALL setMediastreamerAndroidContext(JNIEnv *env, void *context
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Logger
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void java_log(JNIEnv* env, BctbxLogLevel loglevel, jstring jdomain, jstring jmsg) {
const char* domain = jdomain ? env->GetStringUTFChars(jdomain, NULL) : NULL;
const char* msg = jmsg ? env->GetStringUTFChars(jmsg, NULL) : NULL;
BCTBX_SLOG(domain, loglevel) << msg;
if (msg) env->ReleaseStringUTFChars(jmsg, msg);
if (domain) env->ReleaseStringUTFChars(jdomain, domain);
}
JNIEXPORT void JNICALL Java_org_linphone_core_tools_Log_d(JNIEnv* env, jobject thiz, jstring jdomain, jstring jmsg) {
java_log(env, BCTBX_LOG_DEBUG, jdomain, jmsg);
}
JNIEXPORT void JNICALL Java_org_linphone_core_tools_Log_i(JNIEnv* env, jobject thiz, jstring jdomain, jstring jmsg) {
java_log(env, BCTBX_LOG_MESSAGE, jdomain, jmsg);
}
JNIEXPORT void JNICALL Java_org_linphone_core_tools_Log_w(JNIEnv* env, jobject thiz, jstring jdomain, jstring jmsg) {
java_log(env, BCTBX_LOG_WARNING, jdomain, jmsg);
}
JNIEXPORT void JNICALL Java_org_linphone_core_tools_Log_e(JNIEnv* env, jobject thiz, jstring jdomain, jstring jmsg) {
java_log(env, BCTBX_LOG_ERROR, jdomain, jmsg);
}
JNIEXPORT void JNICALL Java_org_linphone_core_tools_Log_f(JNIEnv* env, jobject thiz, jstring jdomain, jstring jmsg) {
java_log(env, BCTBX_LOG_FATAL, jdomain, jmsg);
}
JNIEXPORT void JNICALL Java_org_linphone_core_tools_Log_setDomain(JNIEnv* env, jobject thiz, jstring jdomain) {
const char* domain = jdomain ? env->GetStringUTFChars(jdomain, NULL) : NULL;
bctbx_set_log_level_mask(domain, (int)bctbx_get_log_level_mask(BCTBX_LOG_DOMAIN));
if (domain) env->ReleaseStringUTFChars(jdomain, domain);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class LinphoneJavaBindings {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment