I'm logging this:
Log.d(getClass().getName(), "BLA BLA BLA");
How can I show an int
value? What is the equivalent of C's %d
?
Navigate to device settings and enable Developer Options (see section for ADB logs) Navigate to Developer Options and tap on Take/Submit Bug Report. Select Full Report when prompted to get the full device info along with the logs.
Android allows collecting system logs using Logcat. Log messages can be viewed in a Logcat window in Android Studio, or you can use the command line tool to pull them. Several Android apps are also available in the Google Play store that allow easy access to these tools.
The tag of a system log message is a short string indicating the system component from which the message originates (for example, ActivityManager ). A user-defined tag can be any string that you find helpful, such as the name of the current class (the recommended tag).
You can use string concatenation:
Log.d(getClass().getName(), "value = " + intVar);
or more flexibly (and similar to c-style printf) you can use Java's String.format()
:
Log.d(getClass().getName(), String.format("value = %d", intVar));
String.valueOf()
is what you need if you want string representations of various objects.
And by the way, I'd recommend using slf4j for Android. This way, you don't have to pass class name as the first parameter every single time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With