Skip to content

Commit a4b05c7

Browse files
committed
add debug log 设置
add debug log 设置 IMApplication.setDebugAble(BuildConfig.DEBUG);
1 parent 17584fe commit a4b05c7

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

android/src/main/java/com/netease/im/IMApplication.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.NotificationManager;
44
import android.content.Context;
5+
import android.content.pm.ApplicationInfo;
56
import android.graphics.Color;
67
import android.location.LocationProvider;
78
import android.os.Environment;
@@ -108,6 +109,9 @@ public static void init(Context context, Class mainActivityClass, @DrawableRes i
108109

109110
}
110111

112+
public static void setDebugAble(boolean debugAble){
113+
LogUtil.setDebugAble(debugAble);
114+
}
111115
private static Observer<CustomNotification> notificationObserver = new Observer<CustomNotification>() {
112116
@Override
113117
public void onEvent(CustomNotification customNotification) {
@@ -207,6 +211,7 @@ private static void initStatusBarNotificationConfig(SDKOptions options, Context
207211
// APP默认 StatusBarNotificationConfig 配置修改后,使其生效
208212
userConfig.notificationEntrance = config.notificationEntrance;
209213
userConfig.notificationFolded = config.notificationFolded;
214+
// userConfig.notificationColor = Color.parseColor("#3a9efb");
210215
}
211216
// 持久化生效
212217
// UserPreferences.setStatusConfig(config);
@@ -256,8 +261,16 @@ public static void initKit() {
256261
// init log
257262
String path = StorageUtil.getDirectoryByDirType(StorageType.TYPE_LOG);
258263
LogUtil.init(path, Log.DEBUG);
264+
}
259265

260-
266+
public static boolean isApkDebugable(Context context) {
267+
try {
268+
ApplicationInfo info = context.getApplicationInfo();
269+
return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
270+
} catch (Exception e) {
271+
e.printStackTrace();
272+
}
273+
return false;
261274
}
262275

263276
private static void registerMsgRevokeObserver() {

android/src/main/java/com/netease/im/uikit/common/util/log/LogImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ final class LogImpl {
2626
private static final DateFormat fileNameFormat = new SimpleDateFormat(FILE_FORMAT, Locale.getDefault());
2727

2828
private static final Executor logger = Executors.newSingleThreadExecutor();
29+
private static boolean DEBUG = false;
2930

3031
public static void init(String logPath, int level) {
3132
LogImpl.logPath = logPath;
3233
LogImpl.level = level;
3334
}
34-
35+
public static void setDebugAble(boolean debugAble){
36+
DEBUG = debugAble;
37+
}
3538
public static void i(String tag, String msg) {
3639
i(tag, msg, null);
3740
}
@@ -77,6 +80,9 @@ public static void o(int priority, String tag, String msg) {
7780
}
7881

7982
public static void o(final int priority, final String tag, final String msg, final Throwable tr) {
83+
if(!DEBUG){
84+
return;
85+
}
8086
final long time = System.currentTimeMillis();
8187
final long threadId = Thread.currentThread().getId();
8288
logger.execute(new Runnable() {

android/src/main/java/com/netease/im/uikit/common/util/log/LogUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.netease.im.uikit.common.util.log;
22

33
public class LogUtil {
4+
5+
public static void setDebugAble(boolean debugAble){
6+
LogImpl.setDebugAble(debugAble);
7+
}
48
public static final void init(String logFile, int level) {
59
LogImpl.init(logFile, level);
610
}

0 commit comments

Comments
 (0)