티스토리 뷰

Android

[Android] Timber

혀가 길지 않은 개발자 2021. 5. 2. 23:54

개발할 때 로그 남기고 릴리즈에선 로그 안남기고 싶다!!!!!

Timber? 재목? 목재?


build.gradle (Module:app)

dependencies {
    // Timber
    implementation 'com.jakewharton.timber:timber:4.7.1'
}

 

 

 

 

 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.timberexample">

    <application
        android:allowBackup="true"
        android:name=".TimberApp"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TimberExample">
        <activity android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

android:name=".TimberApp" 

추가!!!

 

 

 

 

 

 

TimberApp.kt

package com.example.timberexample

import android.app.Application
import timber.log.Timber

class TimberApp : Application() {
    override fun onCreate() {
        super.onCreate()
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }
}

디버그 모드 일때만 Timber 로그 남기기!!

Timber.DebugTree() 보면 나무 심는 느낌...

 

 

 

 

 

 

 

MainActivity.kt

package com.example.timberexample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import timber.log.Timber

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Timber.i("나무 심을까")
        Timber.e("나무 심기")
        Timber.d("나무 심자")
    }
}

실행 결과

 

 

 

 

 

 

 

 

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 31
글 보관함