更改日志调试
authorliangzhenying <867174124@qq.com>
Mon, 24 Nov 2025 07:51:47 +0000 (15:51 +0800)
committerliangzhenying <867174124@qq.com>
Mon, 24 Nov 2025 07:51:47 +0000 (15:51 +0800)
ShenYin/ShenYin/Api/LogManager.swift
ShenYin/ShenYin/Cache/ChatCache.swift
ShenYin/ShenYin/UI/Home/Chat/ChatVC.swift
ShenYin/ShenYin/UI/Home/Device/HomeDeviceVC.swift
ShenYin/ShenYin/UI/Mine/Update/BleUpdateVM.swift
ShenYin/ShenYin/UI/common/LogVC.swift

index c188367..fb229e2 100644 (file)
@@ -9,7 +9,7 @@ import Foundation
 
 /// 日记管理
 class Logger {
-    static var isDebug: Bool = true
+    static var isDebug: Bool = false
     
     fileprivate static let shared = Logger()
     private var fileHandle:FileHandle?
@@ -37,6 +37,7 @@ class Logger {
         let path = foldPath + "\(Date().format(.middle)).log"
         if !FileManager.default.fileExists(atPath: path) {
             FileManager.default.createFile(atPath: path, contents: nil, attributes: nil)
+
         }
         return path
     }
index 2a1ac5f..86d53cb 100644 (file)
@@ -32,10 +32,11 @@ class ChatCache {
     private let userDefaults = UserDefaults.standard
     
     func saveList(_ list: [ChatCellModel]) {
+        let maxLength = 10000
         var fullList = [ChatCellModel]()
         fullList.append(contentsOf: list)
-        if fullList.count > 1000{
-            fullList = Array(fullList.dropFirst(fullList.count - 1000))
+        if fullList.count > maxLength{
+            fullList = Array(fullList.dropFirst(fullList.count - maxLength))
         }
         fullList = fullList.filter({$0.content.isNotEmpty})
         
@@ -43,6 +44,7 @@ class ChatCache {
         let filePath = DCFolder.chatCache
         do {
             try encoder.write(to: URL(fileURLWithPath: filePath), options:.atomic)
+            Logger.debug("记录保存成功",filePath)
         } catch {
             Logger.debug("记录保存失败",filePath,error)
         }
@@ -58,4 +60,15 @@ class ChatCache {
         }
         return []
     }
+    func LargeDateDemoSave(){
+        var list = [ChatCellModel]()
+        for i in 0..<10000 {
+            var model = ChatCellModel()
+            model.content = "这是第\(i)数据,jhjah测试数据都是大健康大是的撒辅导费大概大地方佛挡杀佛水电费,电风扇发多少的,防守打法第三方都是佛挡杀佛水电费神鼎飞丹砂方式发到水电费递四方速递咕嘟咕嘟发给电饭锅发的鬼地方"
+            model.type = i%2
+            model.id = i
+            list.append(model)
+        }
+        saveList(list)
+    }
 }
index 5ed525a..b09c4dc 100644 (file)
@@ -108,12 +108,16 @@ class ChatVC:BaseVC{
         
         ///结束对话,但并不会终止正在播放的录音
         JoyGemChatManager.shared().stopChat()
-        ChatCache.shared.saveList(JoySdkManager.shared.dataList)
+        
     }
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         refreshData()
     }
+    override func viewDidDisappear(_ animated: Bool) {
+        super.viewDidDisappear(animated)
+        ChatCache.shared.saveList(JoySdkManager.shared.dataList)
+    }
     override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
         if (keyPath == "isActive") {
             let isOpen = change?[NSKeyValueChangeKey.newKey] as? Bool
index 419a117..bc4a4cd 100644 (file)
@@ -111,6 +111,7 @@ class HomeDeviceVC:BaseVC{
         App.shared.goToPage(BleScanVC())
 //        App.shared.goToPage(CalendarPickerVC())
 //        BleManager.shared.checkSettingsConnected()
+//        ChatCache.shared.LargeDateDemoSave()
     }
     @objc func editAction(){
         let vc = BackgroundVC()
index a710519..52df310 100644 (file)
@@ -18,7 +18,7 @@ class BleUpdateVM:BaseVM{
                 guard let version = version else{
                     return
                 }
-                startCheck(deviceName: deviceName, version: "1.1.0")
+                startCheck(deviceName: deviceName, version: version)
             }
         }
     }
index 65fe7ab..5511b90 100644 (file)
@@ -45,8 +45,13 @@ class LogVC: BaseVC {
         let formatter = DateFormatter()
         formatter.dateFormat = "yyyyMMddHHmmss"
         let name = formatter.string(from: Date())
+        let app_version =  Bundle.main.appVersion ?? "1.0.0"  + "_"
+        let build_version = Bundle.main.appBuild ?? "1"
+        let version = "\(app_version)_\(build_version)"
         
-        let filePath = "\(NSHomeDirectory())/Documents/DeepChords_\(name).txt"
+        let fileName = "DeepChords_" + version + "_\(name).txt"
+        
+        let filePath = "\(NSHomeDirectory())/Documents/\(fileName)"
         let url = URL(fileURLWithPath: filePath)
         let data = self.textView.text.data(using:.utf8)
         do {