I’m currently working with a fork of a third party library for Android and would like to print some information to the Android Studio console (Logcat). Normally you can simply call something like:
Log.i("mytag", "my message here");
But this doesn’t seem to work when calling from a library. Does anyone know how to go about printing to the Android Studio Logcat Console from a library? Any tips or hints pointing me in the right direction would be appreciated! Thanks
UPDATE: This is a native Java/Android library for React-Native. The library I’m working with is a fork of react-native-webview. I don’t know if any of that information is particularly important, but for context I thought I should mention the specifics of what I’m working with.
Advertisement
Answer
There are ways to do it if the default one is not working for you. The one is to use either custom Logger
or use automatically created via this class static factories
Logger.getLogger(String name, String localizationBundle)
or
Logger.getLogger(String name)
).
And then use its log
method which has a lot of overloads for the variety of cases. Its usage is pretty straightforward:
// usual name for the logger is the name of the main class of the library private val logger = Logger.getLogger(MyLibraryMainClass::class.java.name) logger.log(logLevel, message) //where logLevel is Level.WARNING or Level.INFO etc..
Also Log.println(int priority, String tag, String msg) may work.
Also try checking the settings of your logcat – it may be misconfigured. You may try to do it via adb logcat command also.