From 0f91b37f7711481b9671409d0de08873d77060eb Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期三, 20 十二月 2023 17:24:31 +0800
Subject: [PATCH] 2023年12月20日17:24:20

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java |  203 +++++++++++++++++++++++++-------------------------
 1 files changed, 102 insertions(+), 101 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 986d82f..410f0dd 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java
@@ -1,113 +1,114 @@
 package com.hdl.photovoltaic.other;
 
-import android.util.Log;
 
-import com.google.gson.Gson;
+import com.hdl.photovoltaic.utils.TimeUtils;
 
 /**
  * 鏃ュ織閫昏緫
  */
 public class HdlLogLogic {
 
-
-    /**
-     * 鏄惁闇�瑕佹墦鍗�(true涓嶉渶瑕佹墦鍗�)
-     */
-    public static boolean isDebug = false;
-
-    private static volatile HdlLogLogic sHdlLogLogic;
-
-    /**
-     * 鑾峰彇褰撳墠瀵硅薄
-     *
-     * @return HdlLogLogic
-     */
-    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);
-    }
-
-    /**
-     * java鎵撳嵃
-     *
-     * @param mgs 杈撳嚭淇℃伅
-     */
-    public static void print(String mgs) {
-        if (isDebug) {
-            return;
-        }
-        System.out.println(mgs);
-    }
-
-    /**
-     * java鎵撳嵃
-     *
-     * @param tag  鏍囬
-     * @param mgs  閿欒淇℃伅
-     * @param code 閿欒鐮�
-     */
-    public static void print(String tag, String mgs, int code) {
-        if (isDebug) {
-            return;
-        }
-        System.out.println(title + tag + "======" + mgs + "(" + code + ")");
-    }
-
-    /**
-     * java鎵撳嵃
-     *
-     * @param tag  鏍囬
-     * @param mgs  閿欒淇℃伅
-     * @param code 閿欒鐮�
-     */
-    public static void print(String tag, String mgs, String code) {
-        if (isDebug) {
-            return;
-        }
-        System.out.println(title + tag + "======" + mgs + "(" + code + ")");
-    }
-
-    /**
-     * java鎵撳嵃
-     *
-     * @param tag 鏍囬
-     * @param o   閿欒淇℃伅
-     */
-    public static void print(String tag, Object o) {
-
-        if (isDebug) {
-            return;
-        }
-        if (o == null) {
-            System.out.println(title + tag);
-        } else {
-            try {
-                System.out.println(title + tag + "======" + new Gson().toJson(o));
-            } catch (Exception e) {
-                System.out.println(title + tag + "======" + e.getMessage());
-            }
-        }
-    }
-
+    //鏄惁闇�瑕佹墦鍗板埌Logcat涓�(true涓嶉渶瑕佹墦鍗�)
+    public static boolean isPrintLogcat = false;
+    //榛樿鎵撳嵃鏍囬
     private static final String title = "鑷畾涔夎緭鍑烘墦鍗颁俊鎭�:";
 
+
+    /**
+     * java鎵撳嵃
+     *
+     * @param content 鑷畾涔変俊鎭弿杩�
+     *                榛樿涓嶅姞鍏ユ湰鍦版棩蹇�
+     */
+    public static void print(String content) {
+        printBase(content, "0", false);
+    }
+
+    /**
+     * java鎵撳嵃
+     *
+     * @param content   鑷畾涔変俊鎭弿杩�
+     * @param isBoolean 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌)
+     */
+    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;
+        }
+        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