Skip to content

Commit

Permalink
Use log4j2 for Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
Duy Tran committed Dec 20, 2023
1 parent d1a0b13 commit 6d56418
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
20 changes: 20 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ android {
}
}


// https://github.com/Celeral/log4j2-android
configurations.all { config ->
{
if (config.name.startsWith("test") || config.name.contains("Test") && !config.name.contains("Android")) {
exclude group: "com.celeral", module: "log4j2-android"
} else {
exclude group: "org.apache.logging.log4j", module: "log4j-core"
}
}
resolutionStrategy {
force "org.apache.logging.log4j:log4j-api:2.17.2"
}
}


dependencies {
configurations.all {
resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") {
Expand Down Expand Up @@ -79,4 +95,8 @@ dependencies {
implementation "androidx.browser:browser:1.6.0"

implementation project(':modules:programming')

// https://github.com/Celeral/log4j2-android
runtimeOnly "com.celeral:log4j2-android:1.0.0"

}
22 changes: 11 additions & 11 deletions modules/common/src/main/java/com/symja/common/logging/DLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.symja.common.BuildConfig;

/**
* Android logcat
* Setup Crashlytics https://firebase.google.com/docs/crashlytics/get-started?authuser=0
*/
public class DLog {
private static final String TAG = "DLog";
public static boolean TEST_MODE = false;
public static int UITestmode = 0;
/**
* Show log
*/
public static final boolean DEBUG = BuildConfig.DEBUG;
private static final String TAG = "DLog";
public static boolean TEST_MODE = false;
public static int UITestmode = 0;
/**
* Android environment
*/
Expand Down Expand Up @@ -92,13 +94,11 @@ public static void w(Object msg) {
/**
* warning log
*/
public static void w(String TAG, Object msg) {
public static void w(String tag, Object obj) {
if (DEBUG) {
if (ANDROID) {
Log.w(TAG, msg.toString());
} else {
System.err.println(TAG + ": " + msg.toString());
}
if (obj instanceof Throwable) {
w(tag, ((Throwable) obj).getMessage(), (Throwable) obj);
}
}
}

Expand Down Expand Up @@ -213,10 +213,10 @@ public static void i(@NonNull Object msg) {
/**
* info log
*/
public static void i(String tag, @NonNull Object msg) {
public static void i(String tag, @Nullable Object msg) {
if (DEBUG) {
if (ANDROID) {
Log.i(tag, msg.toString());
Log.i(tag, String.valueOf(msg));
} else {
System.err.println(tag + ": " + msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static SyntaxStyle[] loadStyles(Properties properties) {
styles[i] = parseStyle(property);
prev = styles[i];
} catch (Exception e) {
if (DLog.DEBUG) DLog.w(TAG, "loadStyles: failed " + styleName);
if (DLog.DEBUG) DLog.i(TAG, "loadStyles: failed " + styleName);
styles[i] = prev;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void load(Properties properties) {
String color = properties.getProperty(attr.getKey());
put(attr.getKey(), Color.parseColor(color));
} catch (Exception ignored) {
if (DLog.DEBUG) DLog.w(TAG, "load: can not find attr " + attr.getKey());
if (DLog.DEBUG) DLog.i(TAG, "load: can not find attr " + attr.getKey());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.PreferenceManager;

import com.symja.common.analyst.AppAnalytics;
import com.symja.common.analyst.AppAnalyticsEvents;
Expand Down Expand Up @@ -227,8 +227,10 @@ private void loadEditingDocument() {
JSONObject jsonObject = new JSONObject(content);
ProgrammingConsoleDocument examples = new ProgrammingConsoleDocument(jsonObject.toMap());
this.editingDocument.addAll(examples);
} catch (IOException e) {
DLog.i(TAG, e.getMessage());
} catch (Exception e) {
e.printStackTrace();
DLog.w(TAG, e.getMessage());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion symja_android_library

0 comments on commit 6d56418

Please sign in to comment.