Browse Source

v1.0.0开发:优化comm模块输出so的形式

#Suyghur 4 years ago
parent
commit
2a50d23ac6
42 changed files with 175 additions and 51 deletions
  1. 1 1
      build.gradle
  2. 2 1
      demo/build.gradle
  3. 1 0
      demo/src/main/java/com/dolin/demo/DemoApplication.kt
  4. 0 0
      library_comm/.gitignore
  5. 9 4
      library_comm/CMakeLists.txt
  6. 18 11
      library_comm/build.gradle
  7. 0 0
      library_comm/consumer-rules.pro
  8. 0 0
      library_comm/proguard-rules.pro
  9. 0 0
      library_comm/src/main/AndroidManifest.xml
  10. 21 5
      library_comm/src/main/cpp/buffer/buffer.cpp
  11. 5 1
      library_comm/src/main/cpp/buffer/buffer.h
  12. 0 0
      library_comm/src/main/cpp/buffer/buffer_flush.cpp
  13. 0 0
      library_comm/src/main/cpp/buffer/buffer_flush.h
  14. 17 5
      library_comm/src/main/cpp/buffer/buffer_header.cpp
  15. 2 1
      library_comm/src/main/cpp/buffer/buffer_header.h
  16. 0 0
      library_comm/src/main/cpp/buffer/file_flush.cpp
  17. 0 0
      library_comm/src/main/cpp/buffer/file_flush.h
  18. 0 0
      library_comm/src/main/cpp/common.cpp
  19. 0 0
      library_comm/src/main/cpp/common.h
  20. 0 0
      library_comm/src/main/cpp/kit/common_log.h
  21. 17 0
      library_comm/src/main/cpp/kit/time_kit.cpp
  22. 19 0
      library_comm/src/main/cpp/kit/time_kit.h
  23. 0 0
      library_comm/src/main/java/com/dolin/common/Common.kt
  24. 0 0
      library_comm/src/main/java/com/dolin/common/util/CrashUtils.kt
  25. 0 0
      library_comm/src/main/java/com/dolin/common/util/DeviceInfoUtils.kt
  26. 0 0
      library_comm/src/main/java/com/dolin/common/util/FileUtils.kt
  27. 3 3
      library_zap/CMakeLists.txt
  28. 1 1
      library_zap/build.gradle
  29. BIN
      library_zap/src/main/cpp/libs/arm64-v8a/libdolin-common.so
  30. BIN
      library_zap/src/main/cpp/libs/armeabi-v7a/libdolin-common.so
  31. BIN
      library_zap/src/main/cpp/libs/x86/libdolin-common.so
  32. BIN
      library_zap/src/main/cpp/libs/x86_64/libdolin-common.so
  33. 6 2
      library_zap/src/main/cpp/third_part/buffer/buffer.h
  34. 2 1
      library_zap/src/main/cpp/third_part/buffer/buffer_header.h
  35. 13 0
      library_zap/src/main/cpp/third_part/buffer/common_log.h
  36. 21 7
      library_zap/src/main/cpp/zap.cpp
  37. 2 1
      library_zap/src/main/java/com/dolin/zap/entity/Config.kt
  38. 11 3
      library_zap/src/main/java/com/dolin/zap/impl/Record2MMap.kt
  39. 2 2
      library_zap/src/main/java/com/dolin/zap/impl/ZapPrint.kt
  40. 1 1
      library_zap/src/main/java/com/dolin/zap/util/LogFileUtils.kt
  41. 1 1
      settings.gradle
  42. BIN
      soLibs/comm/arm64-v8a/libdolin-comm.so

+ 1 - 1
build.gradle

@@ -1,7 +1,7 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 buildscript {
 
-    ext.COMMON_LIB_DEV_ENABLE = false
+    ext.COMM_LIB_DEV_ENABLE = true
     // 混淆开关
     ext.MINIFY_ENABLE = false
     // ndk版本

+ 2 - 1
demo/build.gradle

@@ -77,6 +77,7 @@ dependencies {
 //    implementation project(':library_caps')
     implementation 'com.google.android.material:material:1.3.0'
     implementation project(':library_zap')
-    implementation project(':library_common')
+    implementation project(':library_comm')
+
 
 }

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

@@ -29,6 +29,7 @@ class DemoApplication : Application() {
                 .setRecordCompressEnable(true)
                 //缓存文件的过期时间
                 .setOverdueDay(3)
+                .setFileSizeLimitDay(1)
                 .create()
         Zap.initialize(this, config)
     }

+ 0 - 0
library_common/.gitignore → library_comm/.gitignore


+ 9 - 4
library_common/CMakeLists.txt → library_comm/CMakeLists.txt

@@ -10,16 +10,21 @@ cmake_minimum_required(VERSION 3.4.1)
 # You can define multiple libraries, and CMake builds them for you.
 # Gradle automatically packages shared libraries with your APK.
 
+#设置库文件的输出目录
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../soLibs/comm/${ANDROID_ABI})
+#message(------ ${PROJECT_SOURCE_DIR}/../lib ------)
+
 include_directories(src/main/cpp/buffer)
+include_directories(src/main/cpp/kit)
 aux_source_directory(src/main/cpp/ DIR_SOURCE)
 aux_source_directory(src/main/cpp/buffer DIR_SOURCE_BUFFER)
-#add_subdirectory(common)
-#include_directories(src/main/cpp/common)
+aux_source_directory(src/main/cpp/kit DIR_SOURCE_KIT)
 add_library(
-        dolin-common
+        dolin-comm
         SHARED
         ${DIR_SOURCE}
         ${DIR_SOURCE_BUFFER}
+        ${DIR_SOURCE_KIT}
 )
 
 # Searches for a specified prebuilt library and stores the path as a
@@ -39,7 +44,7 @@ find_library( # Sets the name of the path variable.
 # build script, prebuilt third-party libraries, or system libraries.
 
 target_link_libraries( # Specifies the target library.
-        dolin-common
+        dolin-comm
         # Links the target library to the log library
         # included in the NDK.
         ${log-lib})

+ 18 - 11
library_common/build.gradle → library_comm/build.gradle

@@ -11,12 +11,20 @@ android {
         minSdkVersion MIN_SDK_VERSION
         targetSdkVersion TARGET_SDK_VERSION
 
-        if (COMMON_LIB_DEV_ENABLE) {
-            externalNativeBuild {
-                cmake {
-                    cppFlags '-std=c++11 -frtti -fexceptions -lz'
-                    abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
-                }
+        externalNativeBuild {
+            cmake {
+                cppFlags '-std=c++11 -frtti -fexceptions -lz'
+                abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
+
+            }
+        }
+
+        if (COMM_LIB_DEV_ENABLE) {
+            packagingOptions {
+                exclude 'lib/arm64-v8a/libdolin-comm.so'
+                exclude 'lib/armeabi-v7a/libdolin-comm.so'
+                exclude 'lib/x86/libdolin-comm.so'
+                exclude 'lib/x86_64/libdolin-comm.so'
             }
         }
     }
@@ -48,13 +56,12 @@ android {
         preDexLibraries = false
     }
 
-    if (COMMON_LIB_DEV_ENABLE) {
-        externalNativeBuild {
-            cmake {
-                path "CMakeLists.txt"
-            }
+    externalNativeBuild {
+        cmake {
+            path "CMakeLists.txt"
         }
     }
+
 }
 
 dependencies {

+ 0 - 0
library_common/consumer-rules.pro → library_comm/consumer-rules.pro


+ 0 - 0
library_common/proguard-rules.pro → library_comm/proguard-rules.pro


+ 0 - 0
library_common/src/main/AndroidManifest.xml → library_comm/src/main/AndroidManifest.xml


+ 21 - 5
library_common/src/main/cpp/buffer/buffer.cpp → library_comm/src/main/cpp/buffer/buffer.cpp

@@ -3,7 +3,7 @@
 //
 
 #include "buffer.h"
-#include "common_log.h"
+#include "../kit/common_log.h"
 
 Buffer::Buffer(char *ptr, size_t buffer_size) : buffer_ptr(ptr), buffer_size(buffer_size), buffer_header(buffer_ptr, buffer_size) {}
 
@@ -11,7 +11,7 @@ Buffer::~Buffer() {
     Release();
 }
 
-void Buffer::InitData(char *log_path, size_t log_path_len, bool _compress) {
+void Buffer::InitData(char *log_path, size_t log_path_len, bool _compress, size_t _limit_size) {
     std::lock_guard<std::recursive_mutex> lck_release(log_mtx);
     memset(buffer_ptr, '\0', buffer_size);
 
@@ -21,11 +21,13 @@ void Buffer::InitData(char *log_path, size_t log_path_len, bool _compress) {
     header.log_path = log_path;
     header.log_len = 0;
     header.compress = _compress;
+    header.limit_size = _limit_size;
 
     buffer_header.InitHeader(header);
     InitCompress(_compress);
+    limit_size = _limit_size;
 
-    data_ptr = (char *) buffer_header.GetPtr();
+    data_ptr = (char *) buffer_header.GetDataPtr();
     write_ptr = (char *) buffer_header.GetWritePtr();
 
     OpenLogFile(log_path);
@@ -40,7 +42,6 @@ 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);
@@ -131,7 +132,7 @@ void Buffer::ChangeLogPath(char *path) {
     if (log_file_ptr != nullptr) {
         CallFileFlush();
     }
-    InitData(path, strlen(path), compress);
+    InitData(path, strlen(path), compress, limit_size);
 }
 
 void Buffer::Clear() {
@@ -162,3 +163,18 @@ bool Buffer::OpenLogFile(const char *path) {
     }
     return false;
 }
+
+bool Buffer::IsCurrentLogFileOversize() {
+    return GetCurrentLogFileSize() >= buffer_header.GetHeader()->limit_size;
+}
+
+size_t Buffer::GetCurrentLogFileSize() {
+    size_t size = 0;
+    if (log_file_ptr != nullptr) {
+        fseek(log_file_ptr, 0, SEEK_END);
+        size = ftell(log_file_ptr);
+    }
+    return size;
+}
+
+

+ 5 - 1
library_common/src/main/cpp/buffer/buffer.h → library_comm/src/main/cpp/buffer/buffer.h

@@ -23,7 +23,7 @@ public:
 
     ~Buffer();
 
-    void InitData(char *log_path, size_t log_path_len, bool _compress);
+    void InitData(char *log_path, size_t log_path_len, bool _compress, size_t _limit_size);
 
     size_t GetLength();
 
@@ -45,6 +45,8 @@ public:
 
     void ChangeLogPath(char *path);
 
+    bool IsCurrentLogFileOversize();
+
 private:
     FILE *log_file_ptr = nullptr;
     FileFlush *file_flush_ptr = nullptr;
@@ -58,6 +60,7 @@ private:
     BufferHeader buffer_header;
     z_stream zStream{};
     bool compress = false;
+    size_t limit_size = 0;
 
     void Clear();
 
@@ -67,6 +70,7 @@ private:
 
     bool OpenLogFile(const char *path);
 
+    size_t GetCurrentLogFileSize();
 
 };
 

+ 0 - 0
library_common/src/main/cpp/buffer/buffer_flush.cpp → library_comm/src/main/cpp/buffer/buffer_flush.cpp


+ 0 - 0
library_common/src/main/cpp/buffer/buffer_flush.h → library_comm/src/main/cpp/buffer/buffer_flush.h


+ 17 - 5
library_common/src/main/cpp/buffer/buffer_header.cpp → library_comm/src/main/cpp/buffer/buffer_header.cpp

@@ -3,6 +3,7 @@
 //
 
 #include "buffer_header.h"
+#include "../kit/common_log.h"
 
 dolin_common::BufferHeader::BufferHeader(void *data, size_t size) : data_ptr((char *) data), data_size(size) {}
 
@@ -21,24 +22,26 @@ void dolin_common::BufferHeader::InitHeader(dolin_common::Header &header) {
         compress = 1;
     }
     memcpy(data_ptr + sizeof(char) + sizeof(size_t) + sizeof(size_t) + header.log_path_len, &compress, sizeof(char));
+    memcpy(data_ptr + sizeof(char) + sizeof(size_t) + sizeof(size_t) + header.log_path_len + sizeof(char), &header.limit_size, sizeof(size_t));
+    LOGD("JNI-> InitHeader : %s", data_ptr);
 }
 
 /**
- * 获取原始的锚点
+ * 获取原始头(不加长度)
  */
 void *dolin_common::BufferHeader::GetOriginPtr() {
     return data_ptr;
 }
 
 /**
- * 获取当前锚点
+ * 获取头部信息(包含头信息长度)
  */
-void *dolin_common::BufferHeader::GetPtr() {
+void *dolin_common::BufferHeader::GetDataPtr() {
     return data_ptr + GetHeaderLen();
 }
 
 /**
- * 获取写入的锚点
+ * 获取写入信息(包含头信息长度和日志长度)
  */
 void *dolin_common::BufferHeader::GetWritePtr() {
     return data_ptr + GetHeaderLen() + GetLogLen();
@@ -64,6 +67,15 @@ dolin_common::Header *dolin_common::BufferHeader::GetHeader() {
 
         char compress = (data_ptr + sizeof(char) + sizeof(size_t) + sizeof(size_t) + log_path_len)[0];
         header->compress = compress == 1;
+
+        size_t limit_size = 0;
+        memcpy(&limit_size, data_ptr + sizeof(char) + sizeof(size_t) + sizeof(size_t) + log_path_len + sizeof(char), sizeof(size_t));
+        header->limit_size = limit_size;
+        LOGD("JNI-> log_len : %d", log_len);
+        LOGD("JNI-> log_path_len : %d", log_path_len);
+        LOGD("JNI-> log_path : %s", log_path);
+        LOGD("JNI-> compress : %c", compress);
+        LOGD("JNI-> limit_size : %d", limit_size);
     }
     return header;
 }
@@ -131,7 +143,7 @@ bool dolin_common::BufferHeader::IsAvailable() {
 }
 
 size_t dolin_common::BufferHeader::CalculateHeaderLen(size_t path_len) {
-    return sizeof(char) + sizeof(size_t) + sizeof(size_t) + path_len + sizeof(char);
+    return sizeof(char) + sizeof(size_t) + sizeof(size_t) + path_len + sizeof(char) + sizeof(size_t);
 }
 
 

+ 2 - 1
library_common/src/main/cpp/buffer/buffer_header.h → library_comm/src/main/cpp/buffer/buffer_header.h

@@ -16,6 +16,7 @@ namespace dolin_common {
         size_t log_path_len;
         char *log_path;
         bool compress;
+        size_t limit_size;
     };
 
     class BufferHeader {
@@ -28,7 +29,7 @@ namespace dolin_common {
 
         void *GetOriginPtr();
 
-        void *GetPtr();
+        void *GetDataPtr();
 
         void *GetWritePtr();
 

+ 0 - 0
library_common/src/main/cpp/buffer/file_flush.cpp → library_comm/src/main/cpp/buffer/file_flush.cpp


+ 0 - 0
library_common/src/main/cpp/buffer/file_flush.h → library_comm/src/main/cpp/buffer/file_flush.h


+ 0 - 0
library_common/src/main/cpp/common.cpp → library_comm/src/main/cpp/common.cpp


+ 0 - 0
library_common/src/main/cpp/common.h → library_comm/src/main/cpp/common.h


+ 0 - 0
library_common/src/main/cpp/buffer/common_log.h → library_comm/src/main/cpp/kit/common_log.h


+ 17 - 0
library_comm/src/main/cpp/kit/time_kit.cpp

@@ -0,0 +1,17 @@
+//
+// Created by #Suyghur, on 4/20/21.
+//
+
+#include "time_kit.h"
+
+std::string TimeKit::GetDate() {
+    time_t now = time(nullptr);
+    tm local_time = *localtime(&now);
+    std::string *date;
+    size_t buffer_size = sizeof(char) * 20;
+    char *buffer = (char *) malloc(buffer_size);
+    strftime(buffer, buffer_size, "%Y-%m-%d", &local_time);
+    date = new std::string(buffer);
+    free(buffer);
+    return *date;
+}

+ 19 - 0
library_comm/src/main/cpp/kit/time_kit.h

@@ -0,0 +1,19 @@
+//
+// Created by #Suyghur, on 4/20/21.
+//
+
+#ifndef DOLIN_TIME_KIT_H
+#define DOLIN_TIME_KIT_H
+
+
+#include <string>
+
+class TimeKit {
+
+public:
+    static std::string GetDate();
+
+};
+
+
+#endif //DOLIN_TIME_KIT_H

+ 0 - 0
library_common/src/main/java/com/dolin/common/Common.kt → library_comm/src/main/java/com/dolin/common/Common.kt


+ 0 - 0
library_common/src/main/java/com/dolin/common/util/CrashUtils.kt → library_comm/src/main/java/com/dolin/common/util/CrashUtils.kt


+ 0 - 0
library_common/src/main/java/com/dolin/common/util/DeviceInfoUtils.kt → library_comm/src/main/java/com/dolin/common/util/DeviceInfoUtils.kt


+ 0 - 0
library_common/src/main/java/com/dolin/common/util/FileUtils.kt → library_comm/src/main/java/com/dolin/common/util/FileUtils.kt


+ 3 - 3
library_zap/CMakeLists.txt

@@ -19,12 +19,12 @@ add_library(
 )
 
 #动态方式加载 STATIC:表示静态的.a的库 SHARED:表示.so的库
-add_library(dolin-common SHARED IMPORTED)
+add_library(dolin-comm SHARED IMPORTED)
 
 #设置要连接的so的相对路径
 #${CMAKE_SOURCE_DIR}:表示CMake.txt的当前文件夹路径
 #${ANDROID_ABI}:编译时会自动根据CPU架构去选择相应的库
-set_target_properties(dolin-common PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libdolin-common.so)
+set_target_properties(dolin-comm PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/../soLibs/comm/${ANDROID_ABI}/libdolin-comm.so)
 
 ##添加第三方头文件
 target_include_directories(dolin-zap PRIVATE ${CMAKE_SOURCE_DIR}/src/main/cpp/third_part)
@@ -47,7 +47,7 @@ find_library( # Sets the name of the path variable.
 
 target_link_libraries( # Specifies the target library.
         dolin-zap
-        dolin-common
+        dolin-comm
         # Links the target library to the log library
         # included in the NDK.
         ${log-lib})

+ 1 - 1
library_zap/build.gradle

@@ -63,5 +63,5 @@ android {
 dependencies {
     implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
     implementation 'androidx.core:core-ktx:1.3.2'
-    compileOnly project(':library_common')
+    compileOnly project(':library_comm')
 }

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


+ 6 - 2
library_zap/src/main/cpp/third_part/buffer/buffer.h

@@ -23,7 +23,7 @@ public:
 
     ~Buffer();
 
-    void InitData(char *log_path, size_t log_path_len, bool _compress);
+    void InitData(char *log_path, size_t log_path_len, bool _compress, size_t _limit_size);
 
     size_t GetLength();
 
@@ -45,6 +45,8 @@ public:
 
     void ChangeLogPath(char *path);
 
+    bool IsCurrentLogFileOversize();
+
 private:
     FILE *log_file_ptr = nullptr;
     FileFlush *file_flush_ptr = nullptr;
@@ -58,15 +60,17 @@ private:
     BufferHeader buffer_header;
     z_stream zStream{};
     bool compress = false;
+    size_t limit_size = 0;
 
     void Clear();
 
     void SetLength(size_t len);
 
-    bool InitCompress(bool compress);
+    bool InitCompress(bool _compress);
 
     bool OpenLogFile(const char *path);
 
+    size_t GetCurrentLogFileSize();
 
 };
 

+ 2 - 1
library_zap/src/main/cpp/third_part/buffer/buffer_header.h

@@ -16,6 +16,7 @@ namespace dolin_common {
         size_t log_path_len;
         char *log_path;
         bool compress;
+        size_t limit_size;
     };
 
     class BufferHeader {
@@ -28,7 +29,7 @@ namespace dolin_common {
 
         void *GetOriginPtr();
 
-        void *GetPtr();
+        void *GetDataPtr();
 
         void *GetWritePtr();
 

+ 13 - 0
library_zap/src/main/cpp/third_part/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

+ 21 - 7
library_zap/src/main/cpp/zap.cpp

@@ -9,6 +9,7 @@
 #include "third_part/buffer/buffer.h"
 #include "third_part/buffer/file_flush.h"
 #include "third_part/buffer/buffer_header.h"
+#include "third_part/buffer/common_log.h"
 
 static FileFlush *pFileFlush = nullptr;
 
@@ -50,7 +51,7 @@ static char *OpenMMap(int buffer_fd, size_t buffer_size) {
 
 
 static jlong InitNative(JNIEnv *env, jclass thiz, jstring buffer_path, jint capacity,
-                        jstring log_path, jboolean compress) {
+                        jstring log_path, jboolean compress, jint limit_size) {
     const char *_buffer_path = env->GetStringUTFChars(buffer_path, JNI_FALSE);
     const char *_log_path = env->GetStringUTFChars(log_path, JNI_FALSE);
     auto buffer_size = static_cast<size_t>(capacity);
@@ -73,7 +74,7 @@ static jlong InitNative(JNIEnv *env, jclass thiz, jstring buffer_path, jint capa
     auto *buffer = new Buffer(buffer_ptr, buffer_size);
     buffer->CallFileFlush(pFileFlush);
     //将 buffer 中的数据清空,并写入日志文件信息
-    buffer->InitData((char *) _log_path, strlen(_log_path), compress);
+    buffer->InitData((char *) _log_path, strlen(_log_path), compress, limit_size);
     buffer->map_buffer = map_buffer;
 
     env->ReleaseStringUTFChars(buffer_path, _buffer_path);
@@ -118,12 +119,25 @@ static void ReleaseNative(JNIEnv *env, jobject thiz, jlong ptr) {
     pFileFlush = nullptr;
 }
 
+
+static jboolean IsCurrentLogFileOversize(JNIEnv *env, jobject thiz, jlong ptr) {
+    auto *buffer = reinterpret_cast<Buffer *>(ptr);
+    if (buffer->IsCurrentLogFileOversize()) {
+        LOGD("JNI -> oversize");
+        return JNI_TRUE;
+    } else {
+        LOGD("JNI -> not oversize");
+        return JNI_FALSE;
+    }
+}
+
 static JNINativeMethod gMethods[] = {
-        {"initNative",          "(Ljava/lang/String;ILjava/lang/String;Z)J", (void *) InitNative},
-        {"writeNative",         "(JLjava/lang/String;)V",                    (void *) WriteNative},
-        {"asyncFlushNative",    "(J)V",                                      (void *) AsyncFlushNative},
-        {"changeLogPathNative", "(JLjava/lang/String;)V",                    (void *) ChangeLogPathNative},
-        {"releaseNative",       "(J)V",                                      (void *) ReleaseNative}
+        {"initNative",               "(Ljava/lang/String;ILjava/lang/String;ZI)J", (void *) InitNative},
+        {"writeNative",              "(JLjava/lang/String;)V",                     (void *) WriteNative},
+        {"asyncFlushNative",         "(J)V",                                       (void *) AsyncFlushNative},
+        {"changeLogPathNative",      "(JLjava/lang/String;)V",                     (void *) ChangeLogPathNative},
+        {"releaseNative",            "(J)V",                                       (void *) ReleaseNative},
+        {"isCurrentLogFileOversize", "(J)Z",                                       (void *) IsCurrentLogFileOversize}
 };
 
 extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {

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

@@ -20,7 +20,8 @@ class Config private constructor(builder: Builder) {
         private set
     var overdueDayMs = 0L
         private set
-    private var fileSizeLimitDayByte = 0
+    var fileSizeLimitDayByte = 0
+        private set
 
 
     init {

+ 11 - 3
library_zap/src/main/java/com/dolin/zap/impl/Record2MMap.kt

@@ -1,12 +1,13 @@
 package com.dolin.zap.impl
 
+import android.util.Log
 import com.dolin.zap.internal.IRecord
 
 /**
  * @author #Suyghur.
  * Created on 4/7/21
  */
-class Record2MMap(bufferPath: String, capacity: Int, logPath: String, compress: Boolean) : IRecord {
+class Record2MMap(bufferPath: String, capacity: Int, private val logPath: String, compress: Boolean, limitSize: Int) : IRecord {
 
     //句柄
     private var ptr = 0L
@@ -14,7 +15,7 @@ class Record2MMap(bufferPath: String, capacity: Int, logPath: String, compress:
     init {
         System.loadLibrary("dolin-zap")
         try {
-            ptr = initNative(bufferPath, capacity, logPath, compress)
+            ptr = initNative(bufferPath, capacity, logPath, compress, limitSize)
         } catch (e: Exception) {
             e.printStackTrace()
         }
@@ -33,6 +34,11 @@ class Record2MMap(bufferPath: String, capacity: Int, logPath: String, compress:
     override fun asyncFlush() {
         if (ptr != 0L) {
             try {
+                Log.d("dolin_zap", "log path $logPath")
+                if (isCurrentLogFileOversize(ptr)) {
+                    //新建文件扩展文件
+//                    changeLogPathNative()
+                }
                 asyncFlushNative(ptr)
             } catch (e: Exception) {
                 e.printStackTrace()
@@ -68,8 +74,10 @@ class Record2MMap(bufferPath: String, capacity: Int, logPath: String, compress:
 
     private external fun releaseNative(ptr: Long)
 
+    private external fun isCurrentLogFileOversize(ptr: Long): Boolean
+
     companion object {
         @JvmStatic
-        private external fun initNative(bufferPath: String, capacity: Int, logPath: String, compress: Boolean): Long
+        private external fun initNative(bufferPath: String, capacity: Int, logPath: String, compress: Boolean, limitSize: Int): Long
     }
 }

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

@@ -52,12 +52,12 @@ class ZapPrint : IPrint {
 
         val logFileName = logDir + File.separator + SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date()) + ".zap"
         if (config.recordEnable) {
-            record2MMap = Record2MMap("$logDir/.cache", 1024 * 400, logFileName, config.compressEnable)
+            record2MMap = Record2MMap("$logDir/zap.cache", 1024 * 400, logFileName, config.compressEnable, config.fileSizeLimitDayByte)
             ZapLifecycle.registerZapLifeCallback(application, record2MMap!!)
         }
 
         Thread {
-            LogFileUtils.cleanOverdueLog(application, logDir, config.overdueDayMs)
+            LogFileUtils.cleanOverdueLog(logDir, config.overdueDayMs)
         }.start()
     }
 

+ 1 - 1
library_zap/src/main/java/com/dolin/zap/util/LogFileUtils.kt

@@ -9,7 +9,7 @@ import java.io.File
  */
 object LogFileUtils {
 
-    fun cleanOverdueLog(context: Context, logFolderPath: String, overdueDayMs: Long) {
+    fun cleanOverdueLog( logFolderPath: String, overdueDayMs: Long) {
         val folder = File(logFolderPath)
         if (!folder.exists()) {
             return

+ 1 - 1
settings.gradle

@@ -1,5 +1,5 @@
 //include ':library_crashlytics'
-include ':library_common'
+include ':library_comm'
 include ':demo'
 //include ':library_caps'
 include ':library_zap'

BIN
soLibs/comm/arm64-v8a/libdolin-comm.so