Browse Source

1,新增另一种打印日志库

yinxueqin 3 năm trước cách đây
mục cha
commit
3a543c95d1
27 tập tin đã thay đổi với 2144 bổ sung91 xóa
  1. 13 8
      app/build.gradle
  2. 4 1
      app/src/main/AndroidManifest.xml
  3. 16 0
      app/src/main/java/cn/hgits/loglibrary/AppApplication.java
  4. 47 2
      app/src/main/java/cn/hgits/loglibrary/MainActivity.java
  5. 9 1
      app/src/main/res/layout/activity_main.xml
  6. 8 5
      build.gradle
  7. 5 5
      debuglogshow/build.gradle
  8. 1 0
      debuglogshow/src/main/AndroidManifest.xml
  9. 1 1
      gradle/wrapper/gradle-wrapper.properties
  10. 8 8
      hgsoftloglibrary/build.gradle
  11. 3 1
      hgsoftloglibrary/consumer-rules.pro
  12. 3 1
      hgsoftloglibrary/proguard-rules.pro
  13. 311 58
      hgsoftloglibrary/src/main/java/com/hgsoft/log/LogUtil.java
  14. 1 0
      hgsoftloglibrarytwo/.gitignore
  15. 129 0
      hgsoftloglibrarytwo/build.gradle
  16. 36 0
      hgsoftloglibrarytwo/consumer-rules.pro
  17. 57 0
      hgsoftloglibrarytwo/proguard-rules.pro
  18. 27 0
      hgsoftloglibrarytwo/src/androidTest/java/com/hgsoft/log/ExampleInstrumentedTest.java
  19. 2 0
      hgsoftloglibrarytwo/src/main/AndroidManifest.xml
  20. 18 0
      hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogInfo.java
  21. 22 0
      hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogLevel.java
  22. 76 0
      hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogManager.kt
  23. 1117 0
      hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogUtil.java
  24. 73 0
      hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/MTAFileNameGenerator.kt
  25. 139 0
      hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/MarsXLogInit.java
  26. 17 0
      hgsoftloglibrarytwo/src/test/java/com/hgsoft/log/ExampleUnitTest.java
  27. 1 0
      settings.gradle

+ 13 - 8
app/build.gradle

@@ -1,16 +1,18 @@
 apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-kapt'
 
 android {
-    compileSdkVersion 30
-    buildToolsVersion "30.0.3"
+    compileSdkVersion 32
+    buildToolsVersion "32.0.0"
 
     defaultConfig {
         applicationId "cn.hgits.loglibrary"
         minSdkVersion 19
-        targetSdkVersion 30
+        targetSdkVersion 32
         versionCode 1
         versionName "1.0"
-
+        multiDexEnabled true
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }
 
@@ -31,14 +33,17 @@ android {
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
 
-    implementation project(path: ':hgsoftloglibrary')
+    //implementation project(path: ':hgsoftloglibrary')
+    implementation project(path: ':hgsoftloglibrarytwo')
     implementation project(path: ':debuglogshow')
 
     //implementation 'com.hgsoft.app:loglibrary:1.2201.1'
+    //implementation 'com.hgsoft.app:loglibrarytwo:1.2201.1'
     //implementation 'com.hgsoft.app:debulogshow:1.2000.0'
-    implementation 'com.google.android.material:material:1.4.0'
-    implementation 'androidx.appcompat:appcompat:1.3.1'
-    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
+    implementation 'androidx.multidex:multidex:2.0.1'
+    implementation 'com.google.android.material:material:1.6.1'
+    implementation 'androidx.appcompat:appcompat:1.4.2'
+    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
     testImplementation 'junit:junit:4.13.2'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

+ 4 - 1
app/src/main/AndroidManifest.xml

@@ -5,13 +5,16 @@
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <!-- normal -->
 
     <application
+        android:name=".AppApplication"
         android:allowBackup="true"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
-        <activity android:name=".MainActivity">
+        <activity android:name=".MainActivity"
+            android:exported="true"
+            >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 

+ 16 - 0
app/src/main/java/cn/hgits/loglibrary/AppApplication.java

@@ -0,0 +1,16 @@
+package cn.hgits.loglibrary;
+
+import androidx.multidex.MultiDexApplication;
+
+/**
+ * <p>用途:</p>
+ *
+ * @author yinxueqin@rd.hgits.cn
+ * 创建时间: 2022/7/19 15:18
+ * @author 更新者:
+ * 更新时间:
+ * 更新说明:
+ * @since 1.0
+ */
+public class AppApplication extends MultiDexApplication {
+}

+ 47 - 2
app/src/main/java/cn/hgits/loglibrary/MainActivity.java

@@ -28,6 +28,7 @@ public class MainActivity extends AppCompatActivity {
 
     AppCompatButton btnInitLog;
     AppCompatButton btnInitTwelveLog;
+    AppCompatButton btnInitTwokbLog;
     AppCompatButton btnCloseLog;
     AppCompatButton btnPrint;
     AppCompatButton btnCreateFourteenLog;
@@ -45,6 +46,7 @@ public class MainActivity extends AppCompatActivity {
 
         btnInitLog = findViewById(R.id.btn_init_log);
         btnInitTwelveLog = findViewById(R.id.btn_init_twelve_log);
+        btnInitTwokbLog = findViewById(R.id.btn_init_two_kb_size_log);
         btnCloseLog = findViewById(R.id.btn_close_log);
         btnPrint = findViewById(R.id.btn_print_log);
         btnCreateFourteenLog = findViewById(R.id.btn_create_fourteen_log);
@@ -55,6 +57,7 @@ public class MainActivity extends AppCompatActivity {
 
         btnInitLog.setOnClickListener(onClickListener);
         btnInitTwelveLog.setOnClickListener(onClickListener);
+        btnInitTwokbLog.setOnClickListener(onClickListener);
         btnCloseLog.setOnClickListener(onClickListener);
         btnPrint.setOnClickListener(onClickListener);
         btnCreateFourteenLog.setOnClickListener(onClickListener);
@@ -90,6 +93,12 @@ public class MainActivity extends AppCompatActivity {
                     LogUtil.i(TAG, systemInfo(MainActivity.this));
                     LogUtil.appenderFlush(false);
                     break;
+                case R.id.btn_init_two_kb_size_log:
+                    LogUtil.i(TAG, "ddddddddddddddddddd");
+                    initTwoKbSizeLog();
+                    LogUtil.i(TAG, systemInfo(MainActivity.this));
+                    LogUtil.appenderFlush(true);
+                    break;
                 case R.id.btn_close_log:
                     LogUtil.appenderClose();
                     break;
@@ -113,7 +122,7 @@ public class MainActivity extends AppCompatActivity {
                     try {
                         currentLogZipFile = LogUtil.getCurrentUserLogFileZip(MainActivity.this);
                     } catch (ZipException e) {
-                        e.printStackTrace();
+                        LogUtil.e(TAG, "异常信息:" + e.getStackTrace());
                     }
                     if (currentLogZipFile != null) {
                         LogUtil.i(TAG, "currentLogZipFile路径:" + currentLogZipFile.getAbsolutePath());
@@ -136,7 +145,7 @@ public class MainActivity extends AppCompatActivity {
                     try {
                         allLogZipFile = LogUtil.getAppAllLogFileZip(MainActivity.this);
                     } catch (ZipException e) {
-                        e.printStackTrace();
+                        LogUtil.e(TAG, "异常信息:" + e.getStackTrace());
                     }
                     if (allLogZipFile != null) {
                         LogUtil.i(TAG, "allLogZipFile路径:" + allLogZipFile.getAbsolutePath());
@@ -237,6 +246,42 @@ public class MainActivity extends AppCompatActivity {
         });
     }
 
+    private void initTwoKbSizeLog() {
+        MarsXLogInit.getInstance().setDebugStatus(BuildConfig.DEBUG);
+        if (BuildConfig.DEBUG) {
+            MarsXLogInit.getInstance().setPUBKEY("");
+            MarsXLogInit.getInstance().setConsoleLogOpen(true);
+            MarsXLogInit.getInstance().setLogFileNamePrefix("Debug_" + System.currentTimeMillis());
+            MarsXLogInit.getInstance().setLogFileMaxSize(2 * 1024);
+        } else {
+            MarsXLogInit.getInstance().setPUBKEY("94e62d97637f357fbd20f0c1f667a67c2f675e158e46015dd0cc54cb3995d0a5d468f7e98b20aec266effb61ec0a2321fb1f8c61af72bf76567921a0d8305005");
+            MarsXLogInit.getInstance().setConsoleLogOpen(false);
+            MarsXLogInit.getInstance().setLogFileNamePrefix("Release_" + System.currentTimeMillis());
+            MarsXLogInit.getInstance().setLogFileMaxSize(2 * 1024);
+        }
+        MarsXLogInit.getInstance().openXlog(this);
+        LogUtil.logPrintInfo((priority, tag, message) -> {
+            switch (priority) {
+                case LEVEL_DEBUG:
+                    Log.d(TAG, message);
+                    break;
+                case LEVEL_ERROR:
+                    Log.e(TAG, message);
+                    break;
+                case LEVEL_INFO:
+                    Log.i(TAG, message);
+                    break;
+                case LEVEL_WARNING:
+                    Log.w(TAG, message);
+                    break;
+                case LEVEL_VERBOSE:
+                default:
+                    Log.v(TAG, message);
+                    break;
+            }
+        });
+    }
+
     private void createFourteenDayLogFile() {
         File externalFileDir = getExternalFilesDir("XLog");
         String logPath = null;

+ 9 - 1
app/src/main/res/layout/activity_main.xml

@@ -23,12 +23,20 @@
         app:layout_constraintTop_toTopOf="parent" />
 
     <androidx.appcompat.widget.AppCompatButton
+        android:id="@+id/btn_init_two_kb_size_log"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="初始化日志限制2kb大小"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/btn_init_log" />
+
+    <androidx.appcompat.widget.AppCompatButton
         android:id="@+id/btn_close_log"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="关闭日志"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@id/btn_init_log" />
+        app:layout_constraintTop_toBottomOf="@id/btn_init_two_kb_size_log" />
 
     <androidx.appcompat.widget.AppCompatButton
         android:id="@+id/btn_print_log"

+ 8 - 5
build.gradle

@@ -3,13 +3,16 @@
 buildscript {
     
     repositories {
+        mavenLocal()
+        maven { url "https://maven.aliyun.com/repository/google" }
+        maven { url "https://maven.aliyun.com/repository/public" }
         google()
-        jcenter()
+        mavenCentral()
         
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:4.1.2'
-        
+        classpath 'com.android.tools.build:gradle:7.2.1'
+        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
@@ -21,9 +24,9 @@ allprojects {
         mavenLocal()
         maven { url "https://nexus.hgits.cn/nexus/repository/hgsoft"}
         maven { url "https://maven.aliyun.com/repository/google" }
-        maven { url "https://maven.aliyun.com/repository/jcenter" }
+        maven { url "https://maven.aliyun.com/repository/public" }
+        maven { url 'https://jitpack.io' }
         google()
-        jcenter()
         mavenCentral()
     }
 }

+ 5 - 5
debuglogshow/build.gradle

@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
 apply plugin: 'maven-publish'
 
 android {
-    compileSdkVersion 30
-    buildToolsVersion "30.0.3"
+    compileSdkVersion 32
+    buildToolsVersion "32.0.0"
 
     defaultConfig {
         minSdkVersion 19
-        targetSdkVersion 30
+        targetSdkVersion 32
         versionCode 121000
         versionName "1.2100.0"
 
@@ -54,8 +54,8 @@ afterEvaluate {
 
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
-    compileOnly 'com.google.android.material:material:1.4.0'
-    compileOnly 'androidx.appcompat:appcompat:1.3.1'
+    compileOnly 'com.google.android.material:material:1.6.1'
+    compileOnly 'androidx.appcompat:appcompat:1.4.2'
     testImplementation 'junit:junit:4.13.2'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

+ 1 - 0
debuglogshow/src/main/AndroidManifest.xml

@@ -6,6 +6,7 @@
 
     <application>
         <activity android:name=".DebugLogActivity"
+            android:exported="true"
             android:launchMode="singleTask" />
         <service android:name=".DebugLogService"
             android:process=":logger" />

+ 1 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip

+ 8 - 8
hgsoftloglibrary/build.gradle

@@ -4,14 +4,14 @@ apply plugin: 'maven-publish'
 //apply from: "https://gitee.com/woyiqiankun/gradle-maven-plugin/raw/master/gradle-mavenizer.gradle"
 
 android {
-    compileSdkVersion 30
-    buildToolsVersion "30.0.3"
+    compileSdkVersion 32
+    buildToolsVersion "32.0.0"
 
     defaultConfig {
         minSdkVersion 19
-        targetSdkVersion 30
-        versionCode 121017
-        versionName "1.2101.7"
+        targetSdkVersion 32
+        versionCode 122025
+        versionName "1.2202.5"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         consumerProguardFiles 'consumer-rules.pro'
@@ -85,7 +85,7 @@ afterEvaluate {
                 // You can then customize attributes of the publication as shown below.
                 groupId = 'com.hgsoft.app'
                 artifactId = 'loglibrary'
-                version = '1.2202.0'
+                version = '1.2202.5'
             }
         }
 
@@ -140,8 +140,8 @@ afterEvaluate {
 
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
-    compileOnly 'androidx.appcompat:appcompat:1.3.1'
-    api 'com.tencent.mars:mars-xlog:1.2.5'
+    compileOnly 'androidx.appcompat:appcompat:1.4.2'
+    api 'com.tencent.mars:mars-xlog:1.2.6'
     api 'net.lingala.zip4j:zip4j:2.1.3'
     testImplementation 'junit:junit:4.13.2'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'

+ 3 - 1
hgsoftloglibrary/consumer-rules.pro

@@ -31,4 +31,6 @@
 }
 -keep class com.hgsoft.log.** { *; }
 # keep Xlog
--keep class com.tencent.mars.** {*;}
+-keep class com.tencent.mars.** {*;}
+# keep zip4j
+-keep class net.lingala.zip4j.** { *;}

+ 3 - 1
hgsoftloglibrary/proguard-rules.pro

@@ -52,4 +52,6 @@
 }
 -keep class com.hgsoft.log.** { *; }
 # keep Xlog
--keep class com.tencent.mars.** {*;}
+-keep class com.tencent.mars.** { *;}
+# keep zip4j
+-keep class net.lingala.zip4j.** { *;}

+ 311 - 58
hgsoftloglibrary/src/main/java/com/hgsoft/log/LogUtil.java

@@ -406,6 +406,24 @@ public final class LogUtil {
         }
     }
 
+    /**
+     * 获取当前使用者今天的日志文件列表,耗时操作,请在子线程调用
+     * @param context 上下文对象
+     * @return 文件列表
+     */
+    public static List<File> getCurrentUserLogFileList(final Context context) {
+        return getLogFileList(context, true, true,false);
+    }
+
+    /**
+     * 获取当天的日志文件列表,耗时操作,请在子线程调用
+     * @param context 上下文对象
+     * @return 文件列表
+     */
+    public static List<File> getCurrentDayLogFileList(final Context context) {
+        return getLogFileList(context, false, true,false);
+    }
+
 
     /**
      * 获取当前使用者今天的日志文件压缩包,耗时操作,请在子线程调用
@@ -445,6 +463,54 @@ public final class LogUtil {
         return zipFile.getFile();
     }
 
+    /**
+     * 获取当天的日志文件压缩包,耗时操作,请在子线程调用
+     *
+     * @param context 上下文对象
+     * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
+     * @throws ZipException 压缩异常
+     */
+    public static File getCurrentDayLogFileZip(final Context context) throws ZipException {
+        return getCurrentDayLogFileZip(context, null);
+    }
+
+    /**
+     * 获取当天的日志文件压缩包,耗时操作,请在子线程调用
+     * @param context  上下文对象
+     * @param sideFiles 额外文件
+     * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
+     * @throws ZipException 压缩异常
+     */
+    public static File getCurrentDayLogFileZip(final Context context, final List<File> sideFiles) throws ZipException {
+        return getCurrentDayLogFileZip(context, sideFiles, null);
+    }
+
+    /**
+     * 获取当天的日志文件压缩包,耗时操作,请在子线程调用
+     * @param context  上下文对象
+     * @param sideFiles 额外文件
+     * @param customZipFileName 压缩包名称,不包含后缀
+     * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
+     * @throws ZipException 压缩异常
+     */
+    public static File getCurrentDayLogFileZip(final Context context, final List<File> sideFiles, final String customZipFileName) throws ZipException {
+        ZipFile zipFile = getLogZipFile(context, false, true,false, customZipFileName);
+        if (sideFiles != null && sideFiles.size() > 0) {
+            zipFile.addFiles(sideFiles);
+        }
+        return zipFile.getFile();
+    }
+
+
+    /**
+     * 获取当前使用者的所有日志文件列表,耗时操作,请在子线程调用
+     * @param context 上下文对象
+     * @return 文件列表
+     */
+    public static List<File> getCurrentUserAllLogFileList(final Context context) {
+        return getLogFileList(context, true, false,false);
+    }
+
 
     /**
      * 获取当前使用者的所有日志文件压缩包,耗时操作,请在子线程调用
@@ -485,6 +551,15 @@ public final class LogUtil {
     }
 
     /**
+     * 获取当前使用者昨天的日志文件列表,耗时操作,请在子线程调用
+     * @param context 上下文对象
+     * @return 文件列表
+     */
+    public static List<File> getCurrentUserYesterdayLogFileList(final Context context) {
+        return getLogFileList(context, true, false,true);
+    }
+
+    /**
      * 获取当前使用者昨天的日志文件压缩包,耗时操作,请在子线程调用
      *
      * @param context 上下文对象
@@ -525,6 +600,66 @@ public final class LogUtil {
         return zipFile.getFile();
     }
 
+
+    /**
+     * 获取昨天的日志文件列表,耗时操作,请在子线程调用
+     * @param context 上下文对象
+     * @return 文件列表
+     */
+    public static List<File> getYesterdayLogFileList(final Context context) {
+        return getLogFileList(context, false, false,true);
+    }
+
+    /**
+     * 获取昨天的日志文件压缩包,耗时操作,请在子线程调用
+     *
+     * @param context 上下文对象
+     * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
+     * @throws ZipException 压缩异常
+     */
+    public static File getYesterdayLogFileZip(final Context context) throws ZipException {
+        return getYesterdayLogFileZip(context, null);
+    }
+
+    /**
+     * 获取昨天的日志文件压缩包,耗时操作,请在子线程调用
+     *
+     * @param context 上下文对象
+     * @param sideFiles 额外文件
+     * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
+     * @throws ZipException 压缩异常
+     */
+    public static File getYesterdayLogFileZip(final Context context, final List<File> sideFiles) throws ZipException {
+        return getYesterdayLogFileZip(context, sideFiles, null);
+    }
+
+
+    /**
+     * 获取昨天的日志文件压缩包,耗时操作,请在子线程调用
+     *
+     * @param context 上下文对象
+     * @param sideFiles 额外文件
+     * @param customZipFileName 压缩包名称,不包含后缀
+     * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
+     * @throws ZipException 压缩异常
+     */
+    public static File getYesterdayLogFileZip(final Context context, final List<File> sideFiles, final String customZipFileName) throws ZipException {
+        ZipFile zipFile = getLogZipFile(context, false, false,true, customZipFileName);
+        if (sideFiles != null && sideFiles.size() > 0) {
+            zipFile.addFiles(sideFiles);
+        }
+        return zipFile.getFile();
+    }
+
+    /**
+     * 获取APP所有日志文件列表,耗时操作,请在子线程调用
+     * @param context 上下文对象
+     * @return 文件列表
+     */
+    public static List<File> getAppAllLogFileList(final Context context) {
+        return getLogFileList(context, false, false, false);
+    }
+
     /**
      * 获取APP所有日志文件压缩包,耗时操作,请在子线程调用
      *
@@ -599,6 +734,51 @@ public final class LogUtil {
         return new ZipFile(logPath);
     }
 
+
+    /**
+     * 获取需要的文件列表
+     * @param context 上下文
+     * @param isCurrent 当前用户
+     * @param isToday 是否只压缩今天
+     * @param isYesterday 是否只压缩明天
+     * @return 文件列表
+     */
+    private static List<File> getLogFileList(final Context context, final boolean isCurrent, final boolean isToday,
+                                         final boolean isYesterday) {
+        File externalFileDir = context.getExternalFilesDir("XLog");
+        String logPath = null;
+        if (externalFileDir != null) {
+            logPath = externalFileDir.getAbsolutePath();
+        }
+        if (TextUtils.isEmpty(logPath)) {
+            LogUtil.i(TAG, "Log缓存目录存在");
+            logPath = context.getFilesDir().getPath() + "/XLog";
+        } else {
+            LogUtil.i(TAG, "Log目录存在");
+        }
+        File logPathFile = new File(logPath);
+        if (logPathFile.exists()) {
+            if (isCurrent) {
+                if (isToday) {
+                    return getCurrentTodayFileList(logPath);
+                } else if (isYesterday) {
+                    return getCurrentYesterdayFileList(logPath);
+                } else {
+                    return getCurrentAllFileList(logPath);
+                }
+            } else {
+                if (isToday) {
+                    return getTodayAllFileList(logPath);
+                } else if (isYesterday) {
+                    return getYesterdayAllFileList(logPath);
+                } else {
+                    return getAllFileList(logPath);
+                }
+            }
+        }
+        return new ArrayList<>();
+    }
+
     /**
      * 创建压缩包
      * @param path 路径
@@ -621,14 +801,40 @@ public final class LogUtil {
             deleteZipFile(logZipDirFile);
 
             ZipFile zipFile = new ZipFile(zipPath + "/" + zipFileName);
-            if (isCurrent && isToday) {
-                getCurrentToday(zipFile, path);
-            } else if (isCurrent && isYesterday) {
-                getCurrentYesterday(zipFile, path);
-            } else if (isCurrent) {
-                getCurrentAll(zipFile, path);
+            if (isCurrent) {
+                if (isToday) {
+                    List<File> currentTodayFileList = getCurrentTodayFileList(path);
+                    if (currentTodayFileList.size() > 0) {
+                        zipFile.addFiles(currentTodayFileList);
+                    }
+                } else if (isYesterday) {
+                    List<File> currentYesterdayFileList = getCurrentYesterdayFileList(path);
+                    if (currentYesterdayFileList.size() > 0) {
+                        zipFile.addFiles(currentYesterdayFileList);
+                    }
+                } else {
+                    List<File> currentAllFileList = getCurrentAllFileList(path);
+                    if (currentAllFileList.size() > 0) {
+                        zipFile.addFiles(currentAllFileList);
+                    }
+                }
             } else {
-                getAll(zipFile, path);
+                if (isToday) {
+                    List<File> todayFileList = getTodayAllFileList(path);
+                    if (todayFileList.size() > 0) {
+                        zipFile.addFiles(todayFileList);
+                    }
+                } else if (isYesterday) {
+                    List<File> yesterdayFileList = getYesterdayAllFileList(path);
+                    if (yesterdayFileList.size() > 0) {
+                        zipFile.addFiles(yesterdayFileList);
+                    }
+                } else {
+                    List<File> allFileList = getAllFileList(path);
+                    if (allFileList.size() > 0) {
+                        zipFile.addFiles(allFileList);
+                    }
+                }
             }
             return zipFile;
         }
@@ -636,11 +842,64 @@ public final class LogUtil {
     }
 
     /**
+     * 获取以一些字符串开头的文件名的文件
+     * @param startsWithName 需要的文件名开头集合
+     * @param path 日志目录
+     * @return 需要的文件
+     */
+    private static List<File> getStartsWithStringFile(final List<String> startsWithName, final String path) {
+        List<File> needLogFile = new ArrayList<>();
+        File logPathFile = new File(path);
+        File[] logFiles = logPathFile.listFiles();
+        if (logFiles != null) {
+            List<File> logFileList = Arrays.asList(logFiles);
+            for (File logFile: logFileList) {
+                boolean isNeed = false;
+                for (String name: startsWithName) {
+                    if (logFile.getName().startsWith(name)) {
+                        isNeed = true;
+                    }
+                }
+                if (isNeed) {
+                    needLogFile.add(logFile);
+                }
+            }
+        }
+        return needLogFile;
+    }
+
+    /**
+     * 获取包含一些字符串的文件名的文件
+     * @param containsName 需要的包含的字符集合
+     * @param path 日志目录
+     * @return 需要的文件
+     */
+    private static List<File> getContainsStringFile(final List<String> containsName, final String path) {
+        List<File> needLogFile = new ArrayList<>();
+        File logPathFile = new File(path);
+        File[] logFiles = logPathFile.listFiles();
+        if (logFiles != null) {
+            List<File> logFileList = Arrays.asList(logFiles);
+            for (File logFile: logFileList) {
+                boolean isNeed = false;
+                for (String name: containsName) {
+                    if (logFile.getName().contains(name)) {
+                        isNeed = true;
+                    }
+                }
+                if (isNeed) {
+                    needLogFile.add(logFile);
+                }
+            }
+        }
+        return needLogFile;
+    }
+
+    /**
      * 获取当前用户今天的日志
-     * @param zipFile 压缩文件
      * @param path 日志目录
      */
-    private static void getCurrentToday(final ZipFile zipFile, final String path) throws ZipException {
+    private static List<File> getCurrentTodayFileList(final String path) {
         List<String> startsWithName = new ArrayList<>();
         //主日志文件
         String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + dateToDay(new Date());
@@ -653,16 +912,14 @@ public final class LogUtil {
             String logFileNameRelease = "Release__" + dateToDay(new Date());
             startsWithName.add(logFileNameRelease);
         }
-        List<File> logFiles = getStartsWithStringFile(startsWithName, path);
-        zipFile.addFiles(logFiles);
+        return getStartsWithStringFile(startsWithName, path);
     }
 
     /**
      * 获取当前用户昨天的日志
-     * @param zipFile 压缩文件
      * @param path 日志目录
      */
-    private static void getCurrentYesterday(final ZipFile zipFile, final String path) throws ZipException {
+    private static List<File> getCurrentYesterdayFileList(final String path) {
         List<String> startsWithName = new ArrayList<>();
         //主日志文件
         String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(1, "yyyyMMdd");
@@ -675,16 +932,14 @@ public final class LogUtil {
             String logFileNameRelease = "Release__" + getPastDate(1, "yyyyMMdd");
             startsWithName.add(logFileNameRelease);
         }
-        List<File> logFiles = getStartsWithStringFile(startsWithName, path);
-        zipFile.addFiles(logFiles);
+        return getStartsWithStringFile(startsWithName, path);
     }
 
     /**
      * 获取当前用户所有的日志
-     * @param zipFile 压缩文件
      * @param path 日志目录
      */
-    private static void getCurrentAll(final ZipFile zipFile, final String path) throws ZipException {
+    private static List<File> getCurrentAllFileList(final String path) {
         List<String> startsWithName = new ArrayList<>();
         //主日志文件
         String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix();
@@ -697,48 +952,38 @@ public final class LogUtil {
             String logFileNameRelease = "Release__";
             startsWithName.add(logFileNameRelease);
         }
-        List<File> logFiles = getStartsWithStringFile(startsWithName, path);
-        zipFile.addFiles(logFiles);
+        return getStartsWithStringFile(startsWithName, path);
     }
 
     /**
-     * 获取所有用户所有的日志
-     * @param zipFile 压缩文件
+     * 获取所有用户今天的日志
      * @param path 日志目录
      */
-    private static void getAll(final ZipFile zipFile, final String path) throws ZipException {
-        File logPathFile = new File(path);
-        File[] logFiles = logPathFile.listFiles();
-        if (logFiles != null) {
-            zipFile.addFiles(Arrays.asList(logFiles));
-        }
+    private static List<File> getTodayAllFileList(final String path) {
+        List<String> containsName = new ArrayList<>();
+        containsName.add(dateToDay(new Date()));
+        return getContainsStringFile(containsName, path);
     }
 
     /**
-     * 获取以一些字符串开头的文件名的文件
-     * @param startsWithName 需要的文件名开头集合
+     * 获取所有用户昨天的日志
      * @param path 日志目录
-     * @return 需要的文件
      */
-    private static List<File> getStartsWithStringFile(final List<String> startsWithName, final String path) {
-        List<File> needLogFile = new ArrayList<>();
+    private static List<File> getYesterdayAllFileList(final String path) {
+        List<String> containsName = new ArrayList<>();
+        String logStartsWith = getPastDate(1, "yyyyMMdd");
+        containsName.add(logStartsWith);
+        return getContainsStringFile(containsName, path);
+    }
+
+    /**
+     * 获取所有用户所有的日志
+     * @param path 日志目录
+     */
+    private static List<File> getAllFileList(final String path) {
         File logPathFile = new File(path);
         File[] logFiles = logPathFile.listFiles();
-        if (logFiles != null) {
-            List<File> logFileList = Arrays.asList(logFiles);
-            for (File logFile: logFileList) {
-                boolean isNeed = false;
-                for (String name: startsWithName) {
-                    if (logFile.getName().startsWith(name)) {
-                        isNeed = true;
-                    }
-                }
-                if (isNeed) {
-                    needLogFile.add(logFile);
-                }
-            }
-        }
-        return needLogFile;
+        return Arrays.asList(logFiles);
     }
 
     /**
@@ -753,22 +998,30 @@ public final class LogUtil {
                                          final boolean isToday, final boolean isYesterday, final String customZipFileName) {
         String zipFileName;
         if (TextUtils.isEmpty(customZipFileName)) {
-            if (isCurrent && isToday) {
-                zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + dateToDay(new Date()) + ".zip";
-            } else if (isCurrent && isYesterday) {
-                zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(1, "yyyyMMdd") + ".zip";
-            } else if (isCurrent) {
-                if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
-                    zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+            if (isCurrent) {
+                if (isToday) {
+                    zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + dateToDay(new Date()) + ".zip";
+                } else if (isYesterday) {
+                    zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(1, "yyyyMMdd") + ".zip";
                 } else {
-                    zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+                    if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
+                        zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+                    } else {
+                        zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+                    }
                 }
             } else {
                 String fileNamePrefix = MarsXLogInit.getInstance().getLogFileNamePrefix().substring(0, MarsXLogInit.getInstance().getLogFileNamePrefix().indexOf("_"));
-                if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
-                    zipFileName = fileNamePrefix + "_all_user_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+                if (isToday) {
+                    zipFileName = fileNamePrefix + "_all_user_" + "_" + dateToDay(new Date()) + ".zip";
+                } else if (isYesterday) {
+                    zipFileName = fileNamePrefix + "_all_user_" + "_" + getPastDate(1, "yyyyMMdd") + ".zip";
                 } else {
-                    zipFileName = fileNamePrefix + "_all_user_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+                    if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
+                        zipFileName = fileNamePrefix + "_all_user_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+                    } else {
+                        zipFileName = fileNamePrefix + "_all_user_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
+                    }
                 }
             }
         } else {

+ 1 - 0
hgsoftloglibrarytwo/.gitignore

@@ -0,0 +1 @@
+/build

+ 129 - 0
hgsoftloglibrarytwo/build.gradle

@@ -0,0 +1,129 @@
+apply plugin: 'com.android.library'
+apply plugin: 'maven-publish'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-kapt'
+// https://github.com/sky-uk/gradle-maven-plugin
+//apply from: "https://gitee.com/woyiqiankun/gradle-maven-plugin/raw/master/gradle-mavenizer.gradle"
+
+android {
+    compileSdkVersion 32
+    buildToolsVersion "32.0.0"
+
+    defaultConfig {
+        minSdkVersion 19
+        targetSdkVersion 32
+        versionCode 122011
+        versionName "1.2201.1"
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles 'consumer-rules.pro'
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled true
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+
+}
+
+tasks.withType(JavaCompile) {
+    options.encoding = 'UTF-8'
+}
+
+task androidJavadocs(type: Javadoc) {
+    failOnError false
+    title = "hgsoftloglibrarytwo ${project.version} API"
+    description "Generates Javadoc"
+    source = android.sourceSets.main.java.srcDirs
+    classpath += files(android.bootClasspath)
+
+    android.libraryVariants.all { variant ->
+        if (variant.name == 'release') {
+            owner.classpath += variant.javaCompileProvider.get().classpath
+        }
+    }
+
+    exclude '**/R.html', '**/R.*.html', '**/index.html', '**/*.kt'
+
+    options {
+        windowTitle("hgsoftloglibrarytwo ${project.version} Reference")
+        locale = 'zh_CN'
+        encoding = 'UTF-8'
+        charSet = 'UTF-8'
+        links("http://docs.oracle.com/javase/8/docs/api/")
+        linksOffline("http://d.android.com/reference", "${android.sdkDirectory}/docs/reference")
+        setMemberLevel(JavadocMemberLevel.PUBLIC)
+    }
+}
+
+task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
+    archiveClassifier.convention('javadoc')
+    archiveClassifier.set('javadoc')
+    from androidJavadocs.destinationDir
+}
+
+task androidSourcesJar(type: Jar) {
+    archiveClassifier.convention('sources')
+    archiveClassifier.set('sources')
+    from android.sourceSets.main.java.srcDirs
+}
+
+afterEvaluate {
+    publishing {
+        publications {
+            // Creates a Maven publication called "release".
+            mavenPublish(MavenPublication) {
+                // Applies the component for the release build variant.
+                from components.release
+                artifact androidSourcesJar
+                artifact androidJavadocsJar
+                // You can then customize attributes of the publication as shown below.
+                groupId = 'com.hgsoft.app'
+                artifactId = 'loglibrarytwo'
+                version = '1.2201.1'
+            }
+        }
+
+        repositories {
+            maven {
+                credentials {
+                    username 'yinxueqin'
+                    password 'hgits1024'
+                }
+
+                url = 'https://nexus.hgits.cn/nexus/repository/hgsoft/'
+            }
+        }
+
+        repositories {
+            maven {
+                credentials {
+                    username '60de898e6da2f73831c32a9d'
+                    password 'G-O=rDpLTK7B'
+                }
+
+                url = 'https://packages.aliyun.com/maven/repository/2117453-release-bMZITa/'
+            }
+        }
+    }
+}
+
+dependencies {
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    compileOnly 'androidx.appcompat:appcompat:1.4.2'
+    api 'com.github.fengzhizi715.SAF-Kotlin-log:core:2.6.8'
+    api 'com.github.fengzhizi715.SAF-Kotlin-log:file:2.6.8'
+    api 'com.github.fengzhizi715.SAF-Kotlin-log:extension:2.6.8'
+    api 'com.github.fengzhizi715.SAF-Kotlin-log:gson:2.6.8'
+    api 'net.lingala.zip4j:zip4j:2.1.3'
+    testImplementation 'junit:junit:4.13.2'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+}

+ 36 - 0
hgsoftloglibrarytwo/consumer-rules.pro

@@ -0,0 +1,36 @@
+-ignorewarnings
+-optimizationpasses 5          # 指定代码的压缩级别
+-dontusemixedcaseclassnames   # 是否使用大小写混合
+-dontpreverify           # 混淆时是否做预校验
+-verbose                # 混淆时是否记录日志
+# 保持行号
+-keepattributes SourceFile,LineNumberTable
+# androidX
+-dontwarn org.xmlpull.v1.XmlPullParser
+-dontwarn org.xmlpull.v1.XmlSerializer
+-keep class org.xmlpull.v1.* {*;}
+-keep class com.google.android.material.** { *; }
+-dontwarn com.google.android.material.**
+-dontnote com.google.android.material.**
+-dontwarn androidx.**
+-keep class androidx.** { *; }
+-keep interface androidx.** { *; }
+
+# kotlin
+-keep class kotlin.** { *; }
+-keep class kotlin.Metadata { *; }
+-dontwarn kotlin.**
+-keepclassmembers class **$WhenMappings {
+    <fields>;
+}
+-keepclassmembers class kotlin.Metadata {
+    public <methods>;
+}
+-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
+    static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
+}
+-keep class com.hgsoft.log.** { *; }
+# keep Xlog
+-keep class com.safframework.log.** {*;}
+# keep zip4j
+-keep class net.lingala.zip4j.** { *;}

+ 57 - 0
hgsoftloglibrarytwo/proguard-rules.pro

@@ -0,0 +1,57 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
+-ignorewarnings
+-optimizationpasses 5          # 指定代码的压缩级别
+-dontusemixedcaseclassnames   # 是否使用大小写混合
+-dontpreverify           # 混淆时是否做预校验
+-verbose                # 混淆时是否记录日志
+# 保持行号
+-keepattributes SourceFile,LineNumberTable
+# androidX
+-dontwarn org.xmlpull.v1.XmlPullParser
+-dontwarn org.xmlpull.v1.XmlSerializer
+-keep class org.xmlpull.v1.* {*;}
+-keep class com.google.android.material.** { *; }
+-dontwarn com.google.android.material.**
+-dontnote com.google.android.material.**
+-dontwarn androidx.**
+-keep class androidx.** { *; }
+-keep interface androidx.** { *; }
+
+# kotlin
+-keep class kotlin.** { *; }
+-keep class kotlin.Metadata { *; }
+-dontwarn kotlin.**
+-keepclassmembers class **$WhenMappings {
+    <fields>;
+}
+-keepclassmembers class kotlin.Metadata {
+    public <methods>;
+}
+-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
+    static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
+}
+-keep class com.hgsoft.log.** { *; }
+# keep Xlog
+-keep class com.safframework.log.** {*;}
+# keep zip4j
+-keep class net.lingala.zip4j.** { *;}

+ 27 - 0
hgsoftloglibrarytwo/src/androidTest/java/com/hgsoft/log/ExampleInstrumentedTest.java

@@ -0,0 +1,27 @@
+package com.hgsoft.log;
+
+import android.content.Context;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+    @Test
+    public void useAppContext() {
+        // Context of the app under test.
+        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+
+        assertEquals("com.hgsoft.log.test", appContext.getPackageName());
+    }
+}

+ 2 - 0
hgsoftloglibrarytwo/src/main/AndroidManifest.xml

@@ -0,0 +1,2 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.hgsoft.log"/>

+ 18 - 0
hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogInfo.java

@@ -0,0 +1,18 @@
+package com.hgsoft.log;
+
+import androidx.annotation.NonNull;
+
+/**
+ * <p>用途:</p>
+ *
+ * @author yinxueqin@rd.hgits.cn
+ * 创建时间: 2021/3/5 13:56
+ * @author 更新者:
+ * 更新时间:
+ * 更新说明:
+ * @since 1.0
+ */
+public interface LogInfo {
+
+    void log(@NonNull final LogLevel priority, @NonNull final String tag, @NonNull final String message);
+}

+ 22 - 0
hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogLevel.java

@@ -0,0 +1,22 @@
+package com.hgsoft.log;
+
+/**
+ * <p>用途:</p>
+ *
+ * @author yinxueqin@rd.hgits.cn
+ * 创建时间: 2021/3/5 13:51
+ * @author 更新者:
+ * 更新时间:
+ * 更新说明:
+ * @since 1.0
+ */
+public enum LogLevel {
+
+    LEVEL_VERBOSE,
+    LEVEL_DEBUG,
+    LEVEL_INFO,
+    LEVEL_WARNING,
+    LEVEL_ERROR,
+    LEVEL_EXTRA;
+
+}

+ 76 - 0
hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogManager.kt

@@ -0,0 +1,76 @@
+package com.hgsoft.log
+
+import android.content.Context
+import android.util.Log
+import com.safframework.log.LogLevel
+import com.safframework.log.configL
+import com.safframework.log.converter.gson.GsonConverter
+import com.safframework.log.printer.FilePrinter
+import com.safframework.log.printer.LogcatPrinter
+import com.safframework.log.printer.file.FileBuilder
+import com.safframework.log.printer.file.clean.FileLastModifiedCleanStrategy
+import com.safframework.log.printer.file.name.DateWithHourFileNameGenerator
+import java.io.File
+
+/**
+ *
+ * <p>用途:</p>
+ *
+ * @author  yinxueqin@rd.hgits.cn
+ * 创建时间: 2022/7/19 14:39
+ * @author  更新者:
+ * 更新时间:
+ * 更新说明:
+ * @since   1.0
+ *
+ */
+object LogManager {
+
+    //设置日志文件的前缀
+    var prefix = "log"
+
+    //日志是否控制台打印
+    var consoleLogOpen = false
+
+    // 设置是否是调试模式,调试模式会把所有日志写入文件,不是调试模式,只会写入大于INFO级别的日志
+    var debugStatus = false
+
+    //文件保存天数,这个保存天数根据文件创建属性决定。最小1天,默认10天
+    var logFileSaveDays = 24 * 60 * 60 * 1000 * 10L
+
+    //单个文件最大字节 0:表示不分割 单位字节
+    var logFileMaxSize: Long = 0
+
+
+    private fun filePrinter(context: Context): FilePrinter {
+        val externalFileDir: File? = context.getExternalFilesDir("XLog")
+        val logPath = if (externalFileDir != null) {
+            externalFileDir.absolutePath
+        } else {
+             "${context.filesDir}/XLog"
+        }
+        return FileBuilder().folderPath(logPath).fileNameGenerator(MTAFileNameGenerator(prefix, logFileMaxSize)).cleanStrategy(
+            FileLastModifiedCleanStrategy(logFileSaveDays)
+        ).build()
+    }
+
+    @JvmStatic
+    fun initLog(context: Context) {
+        configL {
+            logLevel = if (debugStatus) {
+                LogLevel.DEBUG
+            } else {
+                LogLevel.INFO
+            }
+            converter = GsonConverter()
+            displayThreadInfo = false
+            displayClassInfo = false
+        }.apply {
+            addPrinter(filePrinter(context))
+            if (!consoleLogOpen) {
+                removePrinter(LogcatPrinter())
+            }
+        }
+
+    }
+}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1117 - 0
hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/LogUtil.java


+ 73 - 0
hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/MTAFileNameGenerator.kt

@@ -0,0 +1,73 @@
+package com.hgsoft.log
+
+
+import com.safframework.log.printer.file.name.FileNameGenerator
+import java.io.File
+import java.text.SimpleDateFormat
+import java.util.*
+import java.util.concurrent.atomic.AtomicLong
+
+
+/**
+ *
+ * <p>用途:</p>
+ *
+ * @author  yinxueqin@rd.hgits.cn
+ * 创建时间: 2022/7/19 14:45
+ * @author  更新者:
+ * 更新时间:
+ * 更新说明:
+ * @since   1.0
+ *
+ */
+class MTAFileNameGenerator(val prefix: String, val length: Long = 0)  : FileNameGenerator {
+
+    private val mLocalDateFormat: ThreadLocal<SimpleDateFormat> = object : ThreadLocal<SimpleDateFormat>() {
+
+        override fun initialValue() = SimpleDateFormat("yyyyMMdd", Locale.CHINA)
+    }
+
+    private val counter = AtomicLong(0)
+
+    override fun isFileNameChangeable() = true
+
+    override fun generateFileName(logLevel: Int, tag: String, timestamp: Long, lastFileName: String): String {
+        if (lastFileName.isNotEmpty()) {
+
+            val file = File(lastFileName)
+            return if (file.length() < length || length == 0L) {
+                lastFileName
+            } else {
+                val sdf = mLocalDateFormat.get()?:SimpleDateFormat("yyyyMMdd", Locale.CHINA)
+                if (counter.incrementAndGet() > 1) {
+                    prefix + "_" + sdf.let {
+
+                        it.timeZone = TimeZone.getDefault()
+                        it.format(Date(timestamp))
+                    } + "_" + counter.incrementAndGet() + ".xlog.log"
+                } else {
+                    prefix + "_" + sdf.let {
+
+                        it.timeZone = TimeZone.getDefault()
+                        it.format(Date(timestamp)) + ".xlog.log"
+                    }
+                }
+            }
+        } else {
+            val sdf = mLocalDateFormat.get()?:SimpleDateFormat("yyyyMMdd", Locale.CHINA)
+            return if (counter.incrementAndGet() > 1) {
+                prefix + "_" + sdf.let {
+
+                    it.timeZone = TimeZone.getDefault()
+                    it.format(Date(timestamp))
+                } + "_" + counter.incrementAndGet() + ".xlog.log"
+            } else {
+                prefix + "_" + sdf.let {
+
+                    it.timeZone = TimeZone.getDefault()
+                    it.format(Date(timestamp)) + ".xlog.log"
+                }
+            }
+        }
+    }
+}

+ 139 - 0
hgsoftloglibrarytwo/src/main/java/com/hgsoft/log/MarsXLogInit.java

@@ -0,0 +1,139 @@
+package com.hgsoft.log;
+
+import android.content.Context;
+/**
+ * 打印日志初始化设置
+ *
+ * @author  yinxueqin
+ */
+public final class MarsXLogInit {
+
+    private static volatile MarsXLogInit INSTANCE;
+    /**
+     * 加密公钥
+     */
+    private String PUB_KEY = "";
+    /**
+     * 设置日志打开状态,如果日志需要写入不同的文件需要先设置关闭。
+     */
+    private boolean xlogOpenStatus = false;
+
+    private MarsXLogInit(){
+    }
+
+    public static MarsXLogInit getInstance() {
+        if (INSTANCE == null) {
+            synchronized (MarsXLogInit.class) {
+                if (INSTANCE == null) {
+                    INSTANCE = new MarsXLogInit();
+                }
+            }
+        }
+        return INSTANCE;
+    }
+
+    /**
+     * 设置日志打开状态,如果日志需要写入不同的文件需要先设置关闭。
+     *
+     * @param xlogOpenStatus true:已经打开,false:关闭
+     */
+    public void setXlogOpenStatus(final boolean xlogOpenStatus) {
+        this.xlogOpenStatus = xlogOpenStatus;
+    }
+
+    /**
+     * 设置日志文件加密的公钥
+     *
+     * @param pubkey 公钥字符串
+     */
+    public void setPUBKEY(final String pubkey) {
+        PUB_KEY = pubkey;
+    }
+
+    /**
+     * 设置日志文件的前缀
+     *
+     * @param prefix 日志文件前缀
+     */
+    public void setLogFileNamePrefix(final String prefix) {
+        LogManager.INSTANCE.setPrefix(prefix);
+    }
+
+    /**
+     * 获取日志文件前缀
+     *
+     * @return 日志文件前缀
+     */
+    public String getLogFileNamePrefix() {
+        return LogManager.INSTANCE.getPrefix();
+    }
+
+    /**
+     * 设置控制台是否打印
+     *
+     * @param consoleLogOpen true:打印,false:不打印
+     */
+    public void setConsoleLogOpen(final boolean consoleLogOpen) {
+        LogManager.INSTANCE.setConsoleLogOpen(consoleLogOpen);
+    }
+
+    /**
+     * 是否是调试模式
+     * @return 是否是调试模式
+     */
+    public boolean isDebugStatus() {
+        return LogManager.INSTANCE.getDebugStatus();
+    }
+
+    /**
+     * 设置是否是调试模式,调试模式会把所有日志写入文件,不是调试模式,只会写入大于INFO级别的日志
+     *
+     * @param debugStatus true:是,false:否
+     */
+    public void setDebugStatus(final boolean debugStatus) {
+        LogManager.INSTANCE.setDebugStatus(debugStatus);
+    }
+
+    /**
+     * 设置文件保存天数
+     * @param logFileSaveDays 0:表示默认10天,其它表示其它天数,最小不能小于1
+     */
+    public void setLogFileSaveDays(final long logFileSaveDays) {
+        LogManager.INSTANCE.setLogFileSaveDays(logFileSaveDays * 24 * 60 * 60 * 1000);
+    }
+
+    /**
+     * 获取文件缓存天数
+     * @return 缓存天数
+     */
+    public int getLogFileSaveDays() {
+        return (int) (LogManager.INSTANCE.getLogFileSaveDays() / 24 / 60 / 60 / 1000);
+    }
+
+    /**
+     * 获取单个文件最大字节,0:表示不分割
+     * @return 文件最大字节
+     */
+    public long getLogFileMaxSize() {
+        return LogManager.INSTANCE.getLogFileMaxSize();
+    }
+
+    /**
+     * 设置单个文件最大字节,设置后文件会分包。(log_20200710.xlog,log_20200710_1.xlog,log_20200710_2.xlog)
+     * @param logFileMaxSize 最大字节数,单位是字节
+     */
+    public void setLogFileMaxSize(long logFileMaxSize) {
+        LogManager.INSTANCE.setLogFileMaxSize(logFileMaxSize);
+    }
+
+    /**
+     * 打开日志使日志数据能够写入文件和在控制台打印(内部根据 {@link #xlogOpenStatus} 的状态来判断调用是否有效),
+     * 文件默认保存在/sdcard/android/{packageName}/XLog如果前者不可以就保存在context.getFilesDir() + "/XLog"中
+     *
+     * @param context 上下文对象
+     */
+    public void openXlog(final Context context) {
+        LogManager.initLog(context);
+        LogUtil.xlogInitComplete = true;
+    }
+}

+ 17 - 0
hgsoftloglibrarytwo/src/test/java/com/hgsoft/log/ExampleUnitTest.java

@@ -0,0 +1,17 @@
+package com.hgsoft.log;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+public class ExampleUnitTest {
+    @Test
+    public void addition_isCorrect() {
+        assertEquals(4, 2 + 2);
+    }
+}

+ 1 - 0
settings.gradle

@@ -1,4 +1,5 @@
 rootProject.name='loglibrary'
 include ':app'
 include ':hgsoftloglibrary'
+include ':hgsoftloglibrarytwo'
 include ':debuglogshow'