Kaynağa Gözat

feature:增加日志解压的工具

#Suyghur 4 yıl önce
ebeveyn
işleme
e6b25362ac

+ 6 - 0
demo/src/main/java/com/dolin/demo/DemoApplication.kt

@@ -19,9 +19,15 @@ class DemoApplication : Application() {
     override fun onCreate() {
         super.onCreate()
         val config = Config.Builder()
+                //logcat输出最低等级
                 .setLogcatLevel(Level.DEBUG)
+                //是否开启缓存日志
                 .setRecordEnable(true)
+                //缓存日志最低等级
                 .setRecordLevel(Level.DEBUG)
+                //是否开启压缩缓存日志内容
+                .setRecordCompressEnable(true)
+                //缓存文件的过期时间
                 .setOverdueDay(3)
                 .create()
         Zap.initialize(this, config)

+ 4 - 2
library_common/src/main/cpp/buffer/buffer.cpp

@@ -3,6 +3,7 @@
 //
 
 #include "buffer.h"
+#include "common_log.h"
 
 Buffer::Buffer(char *ptr, size_t buffer_size) : buffer_ptr(ptr), buffer_size(buffer_size), buffer_header(buffer_ptr, buffer_size) {}
 
@@ -39,6 +40,7 @@ size_t Buffer::GetLength() {
 }
 
 size_t Buffer::Append(const char *log, size_t len) {
+    LOGD("JNI->%s", log);
     std::lock_guard<std::recursive_mutex> lck_append(log_mtx);
     if (GetLength() == 0) {
         InitCompress(compress);
@@ -139,8 +141,8 @@ void Buffer::Clear() {
     SetLength(GetLength());
 }
 
-bool Buffer::InitCompress(bool is_compress) {
-    compress = compress;
+bool Buffer::InitCompress(bool _compress) {
+    compress = _compress;
     if (compress) {
         zStream.zalloc = Z_NULL;
         zStream.zfree = Z_NULL;

+ 1 - 1
library_common/src/main/cpp/buffer/buffer.h

@@ -63,7 +63,7 @@ private:
 
     void SetLength(size_t len);
 
-    bool InitCompress(bool compress);
+    bool InitCompress(bool _compress);
 
     bool OpenLogFile(const char *path);
 

+ 1 - 0
library_common/src/main/cpp/buffer/buffer_flush.cpp

@@ -29,6 +29,7 @@ void BufferFlush::Write(void *data, size_t len) {
         write_ptr = data_ptr;
     }
 
+
     size_t empty_size = EmptySize();
     if (len < empty_size) {
         memcpy(write_ptr, data, len);

+ 13 - 0
library_common/src/main/cpp/buffer/common_log.h

@@ -0,0 +1,13 @@
+//
+// Created by #Suyghur, on 4/15/21.
+//
+
+#ifndef DOLIN_COMMON_LOG_H
+#define DOLIN_COMMON_LOG_H
+
+#include <android/log.h>
+
+#define TAG "dolin_jni"
+#define LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG,TAG,__VA_ARGS__) // 定义LOGD类型
+#define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,TAG,__VA_ARGS__) // 定义LOGD类型
+#endif //DOLIN_COMMON_LOG_H

+ 23 - 0
library_crashlytics/src/main/java/com/dolin/crashlytics/catcher/JavaCrashCatcher.kt

@@ -5,4 +5,27 @@ package com.dolin.crashlytics.catcher
  * Created on 4/14/21
  */
 class JavaCrashCatcher {
+
+
+
+
+
+    companion object {
+
+        fun getInstance(): JavaCrashCatcher {
+            return JavaCrashCatcherHolder.INSTANCE
+        }
+
+        private object JavaCrashCatcherHolder {
+            val INSTANCE = JavaCrashCatcher()
+        }
+
+        /**
+         * 防止单例对象在反序列化时重新生成对象
+         */
+        private fun readResolve(): Any {
+            return JavaCrashCatcherHolder.INSTANCE
+        }
+    }
+
 }

+ 5 - 1
library_zap/README.md

@@ -1 +1,5 @@
-# Zap日志模块
+# Zap日志模块
+
+## Thanks
+
+- [Tencent/mars](https://github.com/Tencent/mars)

+ 16 - 0
library_zap/log_utils/decompress_log.py

@@ -0,0 +1,16 @@
+import zlib
+
+
+def decompress_zlib(src, dst):
+    src = open(src, "rb+")
+    dst = open(dst, "wb+")
+    handler = zlib.decompressobj(-zlib.MAX_WBITS)
+    data = src.read(1024)
+    while data:
+        dst.write(handler.decompress(data))
+        data = src.read(1024)
+    dst.write(str(handler.flush))
+
+
+if __name__ == "__main__":
+    decompress_zlib("2021-04-15-zap","test.log")

BIN
library_zap/src/main/cpp/libs/arm64-v8a/libdolin-common.so


BIN
library_zap/src/main/cpp/libs/armeabi-v7a/libdolin-common.so


BIN
library_zap/src/main/cpp/libs/x86/libdolin-common.so


BIN
library_zap/src/main/cpp/libs/x86_64/libdolin-common.so


+ 5 - 5
library_zap/src/main/java/com/dolin/zap/entity/Config.kt

@@ -16,7 +16,7 @@ class Config private constructor(builder: Builder) {
         private set
     var recordEnable: Boolean
         private set
-    var catchEnable: Boolean
+    var compressEnable: Boolean
         private set
     private var overdueDayMs = 0L
     private var fileSizeLimitDayByte = 0
@@ -28,7 +28,7 @@ class Config private constructor(builder: Builder) {
         this.logcatLevel = builder.logcatLevel
         this.recordLevel = builder.recordLevel
         this.recordEnable = builder.recordEnable
-        this.catchEnable = builder.catchEnable
+        this.compressEnable = builder.compressEnable
         this.overdueDayMs = builder.overdueDay * 24 * 3600 * 1000L
         this.fileSizeLimitDayByte = builder.fileSizeLimitDay * 1024 * 1024
     }
@@ -49,7 +49,7 @@ class Config private constructor(builder: Builder) {
         internal var logcatLevel = Level.DEBUG
         internal var recordLevel = Level.DEBUG
         internal var recordEnable = true
-        internal var catchEnable = true
+        internal var compressEnable = true
         internal var overdueDay = 3
         internal var fileSizeLimitDay = 15
 
@@ -87,8 +87,8 @@ class Config private constructor(builder: Builder) {
             return this
         }
 
-        fun setCatchEnable(enable: Boolean): Builder {
-            this.catchEnable = enable
+        fun setRecordCompressEnable(enable: Boolean): Builder {
+            this.compressEnable = enable
             return this
         }
 

+ 1 - 1
library_zap/src/main/java/com/dolin/zap/impl/ZapPrint.kt

@@ -51,7 +51,7 @@ class ZapPrint : IPrint {
         this.recordLevel = config.recordLevel
         val logFileName = logDir + File.separator + SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date()) + "-zap"
         if (config.recordEnable) {
-            record2MMap = Record2MMap("$logDir/zap.cache", 1024 * 400, logFileName, false)
+            record2MMap = Record2MMap("$logDir/zap.cache", 1024 * 400, logFileName, config.compressEnable)
             ZapLifecycle.registerZapLifeCallback(application, record2MMap!!)
         }
     }

+ 1 - 1
settings.gradle

@@ -1,4 +1,4 @@
-include ':library_crashlytics'
+//include ':library_crashlytics'
 include ':library_common'
 include ':demo'
 //include ':library_caps'