Programming/Android Library

[Kotlin/Android Library] Local Log

생각하는로뎅 2021. 4. 2. 16:40
반응형

  가끔씩 로컬에 데이터를 저장해서 보고 싶을때가 종종 있었다.

 

  매번 만들기도 귀찮고, 관련 라이브러리 찾기도 귀찮아서 직접 만들기로했다.

 

  차기 버전은 아래와 같이 순서대로 배포될 예정이다.

     

     1. 로컬 파일로 저장하는 기능 -> v1.0.2

     2. 하루씩 파일로 나눠서 저장하는 기능 개발. -> v1.1.0

     3. 용량별로 나눠서 저장하는 기능 개발. -> v1.2.0

     4. 네트워크로 로그를 보낼 수 있도록 개발.

  

 


github.com/costnc/LocalLogProject

 

costnc/LocalLogProject

Contribute to costnc/LocalLogProject development by creating an account on GitHub.

github.com

 

LocalLogProject

 

지원

  • 안드로이드 라이브러리
  • 로컬 파일로 로그를 저장하는 기능
    • support >= Build.VERSION_CODES.JELLY_BEAN(16)
    • support >= Build.VERSION_CODES.Q(29)
  • 날짜별 로그 파일 저장 기능
  • 파일 사이즈별 로그 파일 저장 기능
  • 릴리즈 모드는 log를 기록하지 않습니다.
    • 라이브러리에서 기록하도록 설정 가능
  • use io.reactivex.rxjava3:rxandroid:3.0.0
    • 파일 저장시, 별도의 background 쓰레드를 이용해서 저장하도록 구성되어 있습니다.(rxAndroid 라이브러리 사용)
  • targetSdkVersion 30

 

사용방법

 

Step 1. Add the JitPack repository to your build file

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.costnc:LocalLogProject:1.2.0'
}

Step 3. add application class

<application
        android:name=".ApplicationClass"
        ...
/>

Step 4. init LocalLog in application calss

 

kotlin

class ApplicationClass : Application() {

    override fun onCreate() {
        super.onCreate()

        val builder : LogFile.Builder = LogFile.Builder(applicationContext);
        /* if want save log file : set file name */
        builder.fileName("saveLogFile")
        /* if want save log file : set path */
        builder.path("sub/sub")
        /* if want log files by date */
        builder.asTrunDate()
        /* if want log files by size(byte) */
        builder.trunLogFileSize = 100

        LocalLog
            .initialize(applicationContext)
            /* if >= Build.VERSION_CODES.Q) : download folder save
                cause -> Android 11 issue */
            .saveLogFile(builder.build())
            /* if  want release mode log */
            .enableReleaseLog(false)
            /* if want save log with release */
            .enableReleaseSaveFileLog(false)

    }
    
}

java

public class MainAppliction extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        
        LogFile.Builder builder = new LogFile.Builder(getApplicationContext());
        /* if want save log file : set file name*/
        builder.fileName("saveLogFile");
        /* if want log files by size(byte) */
        builder.asTrunLogFileSize(100);
        /* if want save log file : set path, default is root folder*/
        builder.path("sub/sub");
        /* if want log files by date */
        builder.asTrunDate();

        LocalLog
                .Companion.initialize(MainAppliction.this)
                /* if >= Build.VERSION_CODES.Q) : download folder save
                cause -> Android 11 issue */
                .saveLogFile(builder.build())
                /* if  want release mode log */
                .enableReleaseLog(false)
                /* if want save log with release */
                .enableReleaseSaveFileLog(false);
                
    }
}

Step 5. use Log

 

kotlin

LocalLog.d("lim.sung.jin", "testset1");
LocalLog.d("lim.sung.jin", "testset2");
LocalLog.d("lim.sung.jin", "testset3");

 

java

LocalLog.d("lim.sung.jin", "testset1");
LocalLog.d("lim.sung.jin", "testset2");
LocalLog.d("lim.sung.jin", "testset3");
반응형