Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to log an integer value with log.d?

Tags:

java

android

I am very new to Android and am trying some simple log to get a random background color. I have the code and it returns an integer between 1-256, or so I think. I need to log the value to check if it's OK, but I'm not sure how to log it with Android.. I've been using System.out.println("stuff") to log stuff in the past but I believe that's not how you're supposed to do it in Android.

I have my class:

public static int backgroundColorRandomize()

that returns

return randomRGB;

and I try to log it like this

Log.d(backgroundColorRandomize(), "value = " + randomRGB);

but I need to convert the returned value from backgroundColorRandomize to a String in order for it to log.

I tried java's .toString but I'm not sure I'm using it right.. Any help would be appreciated! Thanks!

like image 277
shan Avatar asked Dec 07 '14 08:12

shan


2 Answers

Log.d("MYINT", "value: " + randomRGB);
like image 170
MineConsulting SRL Avatar answered Oct 17 '22 01:10

MineConsulting SRL


private static final String TAG = YourClass.class.getSimpleName();

...

android.util.Log.d(TAG, String.format("value = %d. random color = %d", randomRGB, backgroundColorRandomize()));

More info:

  • http://developer.android.com/reference/android/util/Log.html
  • https://developer.android.com/tools/debugging/debugging-log.html

Logging libraries: https://android-arsenal.com/tag/57

like image 36
Jared Rummler Avatar answered Oct 16 '22 23:10

Jared Rummler