4

I want to print some logs for debug reason, it seems the print and Timber are all not work with compose, what's the alternative choice?

ccd
  • 5,788
  • 10
  • 46
  • 96
  • 1
    I believe this question is not very useful since it can make people think that logging in Jetpack Compose is different than logging anywhere else. – Vitor Ramos Oct 25 '20 at 22:32
  • You can check out this library to log right on your phone -> https://github.com/girish3/Vlog – Binary Baba Nov 24 '20 at 16:45
  • 2
    @Victor Ramos - The question is actually interesting because Compose provide UI interaction in Android studio itself. If there is a way to print states or layout values without log from phone would be great – pz64_ Aug 15 '21 at 07:45
  • @VitorRamos writing `Log.i(TAG, String)` actually crashes my app, so logging obviously DOESN'T work, or why would he write a question otherwise –  Mar 01 '22 at 17:19

2 Answers2

6

Timber or Log or println all work fine in Compose, If Timber is not worked, then check did you initialize Timber.

Muthukrishnan Rajendran
  • 11,122
  • 3
  • 31
  • 41
1

Initialize Timber as

if (BuildConfig.DEBUG) {
   Timber.plant(DebugTree)
}

inside Application::onCreate() method

Gianluca Veschi
  • 1,239
  • 1
  • 14
  • 20