├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── bosphere │ │ │ │ └── fileloggerdemo │ │ │ │ ├── App.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── bosphere │ │ │ └── fileloggerdemo │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── bosphere │ │ └── fileloggerdemo │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── filelogger ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── bosphere │ │ └── filelogger │ │ ├── FileFormatter.java │ │ ├── Loggable.java │ │ ├── FLConst.java │ │ ├── FLUtil.java │ │ ├── FL.java │ │ ├── FLConfig.java │ │ └── FileLoggerService.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /filelogger/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':filelogger' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FileLogger Demo 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /filelogger/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosphere/Android-FileLogger/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 03 23:34:43 SGT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | **/local.properties 3 | **.DS_Store 4 | .idea 5 | *.class 6 | # Since moved to gradle therefore ignore all *.iml files 7 | *.iml 8 | # Emacs cache 9 | *.*~ 10 | build 11 | **/nbproject/ 12 | misc/scripts/*.json 13 | misc/scripts/*.xml 14 | captures 15 | projectFilesBackup 16 | .externalNativeBuild/ -------------------------------------------------------------------------------- /filelogger/src/main/java/com/bosphere/filelogger/FileFormatter.java: -------------------------------------------------------------------------------- 1 | package com.bosphere.filelogger; 2 | 3 | /** 4 | * Created by yangbo on 22/9/17. 5 | */ 6 | 7 | public interface FileFormatter { 8 | String formatLine(long timeInMillis, String level, String tag, String log); 9 | String formatFileName(long timeInMillis); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /filelogger/src/main/java/com/bosphere/filelogger/Loggable.java: -------------------------------------------------------------------------------- 1 | package com.bosphere.filelogger; 2 | 3 | /** 4 | * Created by yangbo on 22/9/17. 5 | */ 6 | 7 | public interface Loggable { 8 | 9 | void v(String tag, String log); 10 | void d(String tag, String log); 11 | void i(String tag, String log); 12 | void w(String tag, String log); 13 | void e(String tag, String log); 14 | void e(String tag, String log, Throwable tr); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/bosphere/fileloggerdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.bosphere.fileloggerdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | android.enableJetifier=true 13 | android.useAndroidX=true 14 | org.gradle.jvmargs=-Xmx1536m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | # org.gradle.parallel=true 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ============================ 3 | 4 | ## Version 1.0.7 5 | _2018-10-03_ 6 | + Remove redundant manifest declaration 7 | + Migrate to AndroidX 8 | 9 | ## Version 1.0.6 10 | _2018-07-14_ 11 | + Flush buffer to file immediately when logging at error-level 12 | 13 | ## Version 1.0.5 14 | _2018-05-05_ 15 | + Support customize minimum logging level 16 | 17 | ## Version 1.0.4 18 | _2018-03-09_ 19 | + Fix file logging might lead to crashes when file system is unavailable 20 | + Use Android's Log utility to format throwable 21 | 22 | ## Version 1.0.3 23 | _2017-12-23_ 24 | + Comply with background execution limit imposed in Android Oreo 25 | 26 | ## Version 1.0.2 27 | _2017-11-20_ 28 | + Delimit custom message and stack trace with a new line when using `FL.e(String tag, Throwable tr, String fmt, Object... args)` 29 | 30 | ## Version 1.0.1 31 | _2017-09-24_ 32 | + Initial release -------------------------------------------------------------------------------- /app/src/main/java/com/bosphere/fileloggerdemo/App.java: -------------------------------------------------------------------------------- 1 | package com.bosphere.fileloggerdemo; 2 | 3 | import android.app.Application; 4 | import android.os.Environment; 5 | 6 | import com.bosphere.filelogger.FL; 7 | import com.bosphere.filelogger.FLConfig; 8 | import com.bosphere.filelogger.FLConst; 9 | 10 | import java.io.File; 11 | 12 | /** 13 | * Created by yangbo on 22/9/17. 14 | */ 15 | 16 | public class App extends Application { 17 | 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | FL.init(new FLConfig.Builder(this) 22 | .minLevel(FLConst.Level.V) 23 | .logToFile(true) 24 | .dir(new File(Environment.getExternalStorageDirectory(), "file_logger_demo")) 25 | .retentionPolicy(FLConst.RetentionPolicy.FILE_COUNT) 26 | .build()); 27 | FL.setEnabled(true); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/bosphere/fileloggerdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.bosphere.fileloggerdemo; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.bosphere.filelogger", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /filelogger/src/main/java/com/bosphere/filelogger/FLConst.java: -------------------------------------------------------------------------------- 1 | package com.bosphere.filelogger; 2 | 3 | import android.util.SparseArray; 4 | 5 | /** 6 | * Created by bo on 23/9/17. 7 | */ 8 | 9 | public interface FLConst { 10 | 11 | String TAG = "FileLogger"; 12 | 13 | interface Level { 14 | int V = 0; 15 | int D = 1; 16 | int I = 2; 17 | int W = 3; 18 | int E = 4; 19 | } 20 | 21 | SparseArray LevelName = new SparseArray(5) {{ 22 | append(Level.V, "V"); 23 | append(Level.D, "D"); 24 | append(Level.I, "I"); 25 | append(Level.W, "W"); 26 | append(Level.E, "E"); 27 | }}; 28 | 29 | interface RetentionPolicy { 30 | int NONE = 0; 31 | int FILE_COUNT = 1; 32 | int TOTAL_SIZE = 2; 33 | } 34 | 35 | long DEFAULT_MAX_TOTAL_SIZE = 32 * 1024 * 1024; // 32mb 36 | int DEFAULT_MAX_FILE_COUNT = 24 * 7; // ~7 days of restless logging 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Volumes/Data/Users/bo/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /filelogger/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Volumes/Data/Users/bo/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |