2022년 9월 17일 토요일

Timber

Timber

Timber - Android Logging library

Android 에 기본 Log를 출력기능이 있지만 문자수 제약, Releaseg할때도 실수로 로그를 출력등 불편한점 도 있어서 Timber라이브러리를 많이 사용합니다.

Timber는 외부라이브러리서 의존라이브러리추가, application 에 추가 등 작업이 필요합니다.

-build.gradle 에 추가
implementation 'com.jakewharton.timber:timber:5.0.1'
-Applicatioon에서 정의
       if(BuildConfig.DEBUG){
            Timber.plant(Timber.DebugTree())
        }
-사용
 Timber.d("Hello! World")
 Timber.tag("custom tag").d("message...!")
 Timber.tag("custom tag").d("%s message...!", "my")

Timber는 Log의 형태를 별도로 지정할수도 있습니다.

- 정의
class CustomTimberTree: Timber.DebugTree() {
    override fun createStackElementTag(element: StackTraceElement): String? {
        return "${element.className}:${element.lineNumber}#${element.methodName}"
    }
}
- 설정
Timber.plant(CustomTimberTree())

0 comments:

댓글 쓰기