From b2d2e6dcf6ec38a2f24721f2bc925d634a6eb78d Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 05 十二月 2023 18:31:01 +0800
Subject: [PATCH] 2023年12月05日18:30:40

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java |  126 ++++++++++++++++++++++++++++++------------
 1 files changed, 90 insertions(+), 36 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java
index 1a4d07c..75225f8 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java
@@ -1,59 +1,113 @@
 package com.hdl.photovoltaic.other;
 
-import android.util.Log;
+
+import com.hdl.photovoltaic.utils.TimeUtils;
 
 /**
  * 鏃ュ織閫昏緫
  */
 public class HdlLogLogic {
 
+    //鏄惁闇�瑕佹墦鍗板埌Logcat涓�(true涓嶉渶瑕佹墦鍗�)
+    public static boolean isPrintLogcat = false;
+    //榛樿鎵撳嵃鏍囬
+    private static final String title = "鑷畾涔夎緭鍑烘墦鍗颁俊鎭�:";
+
 
     /**
-     * 鏄惁闇�瑕佹墦鍗�(true涓嶉渶瑕佹墦鍗�)
-     */
-    public static boolean isDebug = false;
-
-    private static volatile HdlLogLogic sHdlLogLogic;
-
-    /**
-     * 鑾峰彇褰撳墠瀵硅薄
+     * java鎵撳嵃
      *
-     * @return HdlLogLogic
+     * @param content 鑷畾涔変俊鎭弿杩�
      */
-    public static synchronized HdlLogLogic getInstance() {
-        if (sHdlLogLogic == null) {
-            synchronized (HdlLogLogic.class) {
-                if (sHdlLogLogic == null) {
-                    sHdlLogLogic = new HdlLogLogic();
-                }
-            }
-        }
-        return sHdlLogLogic;
-    }
-
-    /**
-     * android鎵撳嵃
-     *
-     * @param tag 鏍囩
-     * @param mgs 杈撳嚭淇℃伅
-     */
-    public static void print(String tag, String mgs) {
-        if (isDebug) {
-            return;
-        }
-        Log.d(tag, mgs);
+    public static void print(String content) {
+        printBase(content, "0", false);
     }
 
     /**
      * java鎵撳嵃
      *
-     * @param mgs 杈撳嚭淇℃伅
+     * @param content   鑷畾涔変俊鎭弿杩�
+     * @param isBoolean 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌)
      */
-    public static void print(String mgs) {
-        if (isDebug) {
+    public static void print(String content, boolean isBoolean) {
+        printBase(content, "0", isBoolean);
+    }
+
+    /**
+     * java鎵撳嵃
+     *
+     * @param msg       鑷畾涔変俊鎭弿杩�
+     * @param code      鐘舵�佺爜
+     * @param isBoolean 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌)
+     */
+    public static void print(String msg, int code, boolean isBoolean) {
+        printBase(msg, code + "", isBoolean);
+    }
+
+
+    /**
+     * java鎵撳嵃鍜屽瓨鍌ㄦ棩蹇�
+     *
+     * @param msg       淇℃伅鎻忚堪
+     * @param code      鐘舵��
+     * @param isBoolean 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌)
+     */
+    private static void printBase(String msg, String code, boolean isBoolean) {
+        if (isPrintLogcat) {
             return;
         }
-        System.out.println(mgs);
+        CustomLogObject customLogObject = new CustomLogObject();
+        customLogObject.msgOrData = msg;
+        customLogObject.code = code;
+        String json = title;
+        json += customLogObject.getJointMessage();
+        System.out.println(json);
+        if (isBoolean) {
+            writeLog(customLogObject.getJointMessage());
+        }
     }
 
+
+    /**
+     * 鍐欏叆鏃ュ織鍐呭鍒版湰鍦�
+     *
+     * @param strLog 鍐欏叆鍐呭
+     */
+    public static void writeLog(String strLog) {
+        synchronized (HdlLogLogic.class) {
+            strLog = TimeUtils.getTimeFromTimestamp(System.currentTimeMillis()) + "s%" + " " + strLog;//鍔犳墦鍗版椂闂�(s%鍗犱綅绗︼紝璁剧疆鏄剧ず鏃堕棿涓嶅悓瀛椾綋棰滆壊)
+            HdlFileLogic.getInstance().appendFile(HdlFileLogic.getInstance().getLogFileNamePath(), strLog);
+        }
+    }
+
+    /**
+     * 璇诲彇鏃ュ織鍐呭
+     *
+     * @return 鏃ュ織鍐呭
+     */
+    public static String readLog() {
+        return HdlFileLogic.getInstance().readFile(HdlFileLogic.getInstance().getLogFileNamePath());
+    }
+
+
+    /**
+     * 鑷畾涔夋棩蹇楃被
+     */
+    static class CustomLogObject {
+        //淇℃伅鎻忚堪
+        public String msgOrData = "";
+        //鐘舵�佺爜
+        public String code = "0";
+
+        public String getJointMessage() {
+
+            if ("0".equals(code)) {
+                return msgOrData;
+            }
+            return msgOrData + "(" + code + ")";
+
+        }
+    }
+
+
 }

--
Gitblit v1.8.0