Im in the proccess of making my jetpack compose li...
# library-development
t
Im in the proccess of making my jetpack compose library work with on compose multiplatform, i was wondering what is the best way to print log statments in debug mode? in Android i was just using
Log.d
and i currently just print them with
println
but i guess its not the best option, i there a better way to do it? do i have to use a library for that?
m
Usually I expect libraries to not log things. If you need to, you can add APIs where users can add their own, see https://publicobject.com/2022/05/01/eventlisteners-are-good/
👀 2
For compose, you could use a CompositionLocal for an example
👍 1
t
Thanks for the article guess i can cut off most of the logs on my library, will give it a second thought
z
If you’re just logging locally for your own debugging, the simplest thing is probably to stick with println and use a const bool flag to guard it, which can be removed from the bytecode by certain tools when it’s disabled. We do that in compose a lot (and have tests to make sure we don’t accidentally enable the flag on the main branch)
👍 2
t
can you please point me at what kind of tools can be used to remove logs from the generated bytecode on such conditions?
m
Proguard/R8 should do this automatically if the bool flag is a compile time constant
☝🏻 1
It's only JVM though 🤔 , I'm not sure what the tooling is for native/JS
t
Thanks so much for the help and suggestions, i went with adding custom apis just in case users would like to print logs
👍 1