Browse Source

3.0 optimize:日志优化

xwh 1 month ago
parent
commit
9f736b80b1

+ 4 - 1
app/src/main/java/com/hh/arome/activity/MainActivity.java

@@ -442,7 +442,10 @@ public class MainActivity extends BaseMVPActivity<MainPresenter> implements View
     public void setConfigStatusText(String text) {
         runOnUiThread(() -> {
             if (tvConfigStatus != null && !TextUtils.isEmpty(text)) {
-                tvConfigStatus.setText(text);
+                tvConfigStatus.setText(text);String logLine = (new Throwable().getStackTrace())[0].toString();
+                UploadLogUtils.sendLogs("硬件模块-初始化",
+                        "",logLine,text);
+
             }
         });
     }

+ 3 - 2
lib_ampe/src/main/java/com/hh/lib_ampe/utils/AromeInvoker.java

@@ -29,6 +29,7 @@ import com.hh.lib_base.bean.device.DeviceConfigResultBean;
 import com.hh.lib_base.log.AppLogUtils;
 import com.hh.lib_base.log.UploadLogUtils;
 import com.hh.lib_base.utils.GsonUtils;
+import com.hh.lib_base.utils.ShortenLogUtils;
 import com.hh.lib_base.utils.StringUtils;
 import com.hh.lib_base.utils.device.DeviceUtils;
 
@@ -446,8 +447,8 @@ public class AromeInvoker {
                 // 日志行数——对应web端"日志标签"
                 String logLine = (new Throwable().getStackTrace())[0].toString();
                 StringBuilder logContentSb = new StringBuilder();
-                logContentSb.append(eventData)
-                        .append(WARP).append("aromeResponse = ")
+                logContentSb.append(ShortenLogUtils.shortenLog(eventData));
+                logContentSb.append(WARP).append("aromeResponse = ")
                         .append(response);
                 UploadLogUtils.sendLogs(type,"---主动推送给小程序结果---"+eventName,logLine,logContentSb.toString());
 

+ 76 - 0
lib_base/src/main/java/com/hh/lib_base/utils/ShortenLogUtils.java

@@ -0,0 +1,76 @@
+package com.hh.lib_base.utils;
+
+import android.text.TextUtils;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Description: $ 缩短日志
+ * @author xwh
+ * time 2024/12/3
+ **/
+public class ShortenLogUtils {
+
+    /**
+     *
+     * @author xwh
+     * Time 2024/12/3
+     * Description: 不上传base64字段具体信息
+     *
+    **/
+    public static String shortenLog(String jsonStr){
+        try { //TODO 网络日志,优化显示某些字段长度,减少服务器压力
+            JSONObject uploadJson=new JSONObject(jsonStr);
+            //下面就是具体字段,模拟下方字段取值修改就可以
+            String photoBase64 =uploadJson.optString("photoBase64");
+            if(!TextUtils.isEmpty(photoBase64)){
+                uploadJson.put("photoBase64","size->"+photoBase64.length());
+            }
+
+            return uploadJson.toString();
+
+        } catch (JSONException e) {
+            return jsonStr;
+        }catch (Exception e){
+            return jsonStr;
+        }
+
+    }
+
+    /**
+     *
+     * @author xwh
+     * Time 2024/12/3
+     * Description: 根据 dataKey  去优化内部的Base64字段
+     *
+    **/
+    public static String shortenLog(String rootJsonStr,String dataKey){
+        try { //TODO 网络日志,优化显示某些字段长度,减少服务器压力
+            JSONObject uploadJson=new JSONObject(rootJsonStr);
+
+            String dataStr=uploadJson.optString(dataKey);
+
+            if(TextUtils.isEmpty(dataStr)){
+                return rootJsonStr;
+            }
+            //TODO 根据 dataKey 获取JSON对象
+            JSONObject data=new JSONObject(dataStr);
+
+            //下面就是具体字段,模拟下方字段取值修改就可以
+            String photoBase64 =data.optString("photoBase64");
+            if(!TextUtils.isEmpty(photoBase64)){
+                data.put("photoBase64","size->"+photoBase64.length());
+            }
+
+
+            uploadJson.put(dataKey,data);
+            return uploadJson.toString();
+        } catch (JSONException e) {
+            return rootJsonStr;
+        }catch (Exception e){
+            return rootJsonStr;
+        }
+
+    }
+}

+ 1 - 1
lib_face/src/main/java/com/hh/lib_face/BPaaSApiInvoker.java

@@ -394,7 +394,7 @@ public class BPaaSApiInvoker {
                                 .append("bPaasVerifyID = ").append(bPaasVerifyID).append(WARP)
                                 .append("bundle = ").append(GsonUtils.getGson().toJson(bundle));
 
-                        UploadLogUtils.sendLogs("刷脸返回数据",Constants.Ampe.ACTION_FACE,logLine,logContentSb.toString());
+                        UploadLogUtils.sendLogs("刷脸返回数据","onEvent",logLine,logContentSb.toString());
                         // 将resultStr转成json
                         InvokeScanFaceBean invokeScanFaceBean = GsonUtils.getGson().fromJson(resultStr, InvokeScanFaceBean.class);
                         if (invokeScanFaceBean.getCode() == 0) {

+ 1 - 1
lib_idcard/src/main/java/com/hh/lib_idcard/IDCardInvoler.java

@@ -207,7 +207,7 @@ public class IDCardInvoler {
                 }
                 lastErrMsg = idCardError.getMessage();
                 String logLine = (new Throwable().getStackTrace())[0].toString();
-                UploadLogUtils.sendLogs(Constants.LogcatValue.LOG_NODE_IDCARD, "", logLine, lastErrMsg);
+                UploadLogUtils.sendLogs(false,Constants.LogcatValue.LOG_NODE_IDCARD, "", logLine, lastErrMsg);
             }
         });
     }

+ 1 - 1
lib_infrared/src/main/java/com/hh/lib_infrared/InfraredInvoker.java

@@ -313,7 +313,7 @@ public class InfraredInvoker {
             logContentSb.append("原始数据 = ").append(new Gson().toJson(ComRecData.bRec)).append(WARP)
                     .append("原始数据MyFunc转换 = ").append(MyFunc.ByteArrToHex(ComRecData.bRec))
                     .append("原始数据转换result = ").append(result);
-            UploadLogUtils.sendLogs(logNode, EVENT_INFRARED_INDUCTION_LISTENER, logLine, logContentSb.toString());
+            UploadLogUtils.sendLogs(false,logNode, EVENT_INFRARED_INDUCTION_LISTENER, logLine, logContentSb.toString());
 
         }
 

+ 2 - 2
lib_nfc/src/main/java/com/lib_nfc/cpu/CPUCardInvoker.java

@@ -100,8 +100,8 @@ public class CPUCardInvoker {
         @Override
         public void onLogInfo(String errMsg) {
             String logLine = (new Throwable().getStackTrace())[0].toString();
-            UploadLogUtils.sendLogs(NET_LOGCAT,Constants.LogcatValue.LOG_NFC_CPU,
-                    "",logLine,errMsg,false);
+            UploadLogUtils.sendLogs(false,Constants.LogcatValue.LOG_NFC_CPU,
+                    "",logLine,errMsg);
         }
     };
 

+ 2 - 2
lib_nfc/src/main/java/com/lib_nfc/m1/M1CardInvoker.java

@@ -238,8 +238,8 @@ public class M1CardInvoker {
         @Override
         public void onLogInfo(String errMsg) {
             String logLine = (new Throwable().getStackTrace())[0].toString();
-            UploadLogUtils.sendLogs(NET_LOGCAT,Constants.LogcatValue.LOG_M1CARD,
-                    "",logLine,errMsg,false);
+            UploadLogUtils.sendLogs(false,Constants.LogcatValue.LOG_M1CARD,
+                    "",logLine,errMsg);
         }
     };
     private void initM1(){

+ 1 - 6
lib_qr/lib_dx_multi_qr/src/main/java/com/hh/lib_dx_multi_qr/DxMultiQRScan.java

@@ -24,17 +24,12 @@ public class DxMultiQRScan extends BaseQRScan {
         init(listener);
         switch (DxCardReader.getInstance().getStatusEnum()){
             case SUCCESS:
-                String logLine = (new Throwable().getStackTrace())[0].toString();
-                UploadLogUtils.sendLogs(LOG_NODE_QR,"",
-                        logLine,"二维码-" + "USB-初始化成功");
+
                 if(listener!=null){
                     listener.onInitSuccess();
                 }
                 break;
             case  FAIL:
-                String logLine2 = (new Throwable().getStackTrace())[0].toString();
-                UploadLogUtils.sendLogs(LOG_NODE_QR,"",
-                        logLine2,"二维码-" + "USB-初始化失败");
                 if(listener!=null){
                     listener.onInitFail(-1,"");
                 }

+ 5 - 10
lib_qr/lib_dx_qr/src/main/java/com/hh/lib_dx_qr/DxGeneralQRScan.java

@@ -185,7 +185,7 @@ public class DxGeneralQRScan extends BaseQRScan {
             logContentSb .append("原始数据 = ").append(new Gson().toJson(ComRecData.bRec)).append(WARP)
                     .append("原始数据MyFunc转换 = ").append(MyFunc.ByteArrToHex(ComRecData.bRec)).append(WARP)
                     .append("qrData = ").append(qrData);
-            UploadLogUtils.sendLogs(Constants.LogcatValue.LOG_NODE_QR,"",logLine,logContentSb.toString());
+            UploadLogUtils.sendLogs(false,Constants.LogcatValue.LOG_NODE_QR,"",logLine,logContentSb.toString());
             onScanSuccess(qrData);
         }
 
@@ -227,22 +227,17 @@ public class DxGeneralQRScan extends BaseQRScan {
                             statusEnum= InitStatusEnum.SUCCESS;
                             //todo "二维码-" + "USB-扫码头初始化成功...."
                             mHandler.removeMessages(3);
-                            String logLine = (new Throwable().getStackTrace())[0].toString();
-                            UploadLogUtils.sendLogs(LOG_NODE_QR,"",
-                                    logLine,"二维码-" + "USB-初始化成功");
                         }
 
                         @Override
                         public void onInitFail(int code, String errMsg) {
-                            if(qrInitListener!=null){
-                                qrInitListener.onInitFail(code, errMsg);
-                            }
+
                             //todo "二维码-" + "USB-扫码头初始化失败....\n" + errMsg
                             if(statusEnum!=InitStatusEnum.FAIL){
                                 statusEnum=InitStatusEnum.FAIL;
-                                String logLine = (new Throwable().getStackTrace())[0].toString();
-                                UploadLogUtils.sendLogs(LOG_NODE_QR,"",
-                                        logLine,"二维码-" + "USB-初始化失败" + errMsg);
+                                if(qrInitListener!=null){
+                                    qrInitListener.onInitFail(code, errMsg);
+                                }
                             }
                             getmHandler().removeMessages(3);
                             getmHandler().sendEmptyMessageDelayed(3,5000);