일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 코틀린 에러 핸들링
- android compose orbit
- power menu 라이브러리
- BOJ
- 안드로이드 커스텀 뷰
- Coroutine
- Android Compose Navigation
- 백준
- 코루틴 공식 문서
- 안드로이드 컴포즈
- 스레드 vs 코루틴
- hilt
- Hilt 에러
- RecyclerView Sticky Header
- 안드로이드 무한 스크롤
- Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException
- viewmodel
- runCatching
- Sticky Header RecyclerView
- Android Compose
- 힐트
- Android Custom View
- 코루틴
- 코루틴 공식문서
- AAC ViewModel
- power menu
- 백준 2615
- Thread vs Coroutine
- Kotlin Serialization
- android orbit
- Today
- Total
Beeeam
Timber Library 본문
Timber
Android에서 많이 사용되는 로깅 라이브러리이다. 기존의 Log 클래스보다 더 간결하게 로그를 출력할 수 있고, release할 때 로그가 노출되지 않는 장점이 있다.
// Log 클래스 사용
Log.d("TAG", "내용")
// Timber 사용
Timber.d("내용")
코드를 보면 더 간결하게 로그를 찍을 수 있는 것을 확인할 수 있다.
사용
https://github.com/JakeWharton/timber
GitHub - JakeWharton/timber: A logger with a small, extensible API which provides utility on top of Android's normal Log class.
A logger with a small, extensible API which provides utility on top of Android's normal Log class. - GitHub - JakeWharton/timber: A logger with a small, extensible API which provides utility on...
github.com
위의 링크에 설치하는 방법이 자세히 설명 되어 있다.
1. 라이브러리를 implementation 해준다. (app단의 build gradle에 추가)
dependencies {
implementation 'com.jakewharton.timber:timber:5.0.1'
}
2. 처음 실행되는 클래스에서 Timber를 초기화 한다.
- Activity 클래스의 onCreate()
- Application 클래스의 onCreate()
두 시점 중에서 선택해서 초기화 하면 된다. Timber Git hub에는 Application 클래스의 onCreate()에서 초기화를 한다고 되어 있는데 구글링을 해보면 Activity의 onCreate()에서 초기화 한다는 글도 많이 있다. 테스트를 해보니 각각의 두 시점에서 초기화해도 문제 없이 사용되는 것을 알 수 있었다.
(공식 Git hub에서 Application class에서 초기화 하라고 했으니 Application class에서 초기화 하였음)
class ApplicationClass: Application() {
override fun onCreate() {
super.onCreate()
Timber.plant(Timber.DebugTree())
}
}
3. AndroidManifest.xml에 Application class를 지정한다.
<application
android:name=".ApplicationClass"
...
>
...
</application>
4. 원하는 지점에서 Timber를 사용하여 로그를 확인한다.
class SampleActivity : AppCompatActivity {
...
Timber.d("Timber Test(Activity)")
...
}
그러면 밑처럼 Timber를 호출한 클래스가 Tag이고 지정한 내용이 출력되는 로그를 확인할 수 있다.
'Android' 카테고리의 다른 글
Power Menu (0) | 2023.06.27 |
---|---|
Bottom Navigation View (0) | 2023.06.27 |
Splash screen api (0) | 2023.06.01 |
Custom View (2) | 2023.05.13 |
앱 내부에서 카메라 실행시키기 (3) | 2023.04.19 |