Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you log an int on Android?

Tags:

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?

like image 927
Abramodj Avatar asked Dec 20 '10 16:12

Abramodj


People also ask

How do you record a log on an Android phone?

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.

Is there a system log in Android?

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.

What is a log message in Android?

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).


2 Answers

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)); 
like image 93
codelark Avatar answered Sep 28 '22 03:09

codelark


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.

like image 36
darioo Avatar answered Sep 28 '22 03:09

darioo