0

I copied a sample from MotionEvent javadoc. It did not print anything to logcat so i looked more deeply and realized that it uses System.out instead of Log. Is it a bug in Javadoc or did I miss something and is it supposed to print somewhere I can see?

void printSamples(MotionEvent ev) {
 final int historySize = ev.getHistorySize();
 final int pointerCount = ev.getPointerCount();
 for (int h = 0; h < historySize; h++) {
     System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
     for (int p = 0; p < pointerCount; p++) {
         System.out.printf("  pointer %d: (%f,%f)",
             ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
     }
 }
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
  • On most devices `System.out` gets output to logcat with log level `info`. Make sure you don't have that level filtered out. – laalto Dec 15 '15 at 21:20
  • IDE is connected to Nexus 4 with Android 5.1. I cannot see it there. Log.d messages are present. – Leos Literak Dec 15 '15 at 21:24
  • @LeosLiterak `Log.d` is _debug_. I think `info` is one level below. Edit: I was wrong `info` has higher priority than `debug` and should be shown. – Gumbo Dec 15 '15 at 21:25
  • 1
    @Gumbo I wrote it because if debug is displayed than info must be displayed as well. – Leos Literak Dec 15 '15 at 21:27
  • @laalto so the answer is that they used system.out because it is supposed to work in most cases (except my phone). – Leos Literak Dec 15 '15 at 21:29

1 Answers1

2

System.out is a PrintStream and provides handy helpers such as printf() that Log does not. Also on many configurations, System.out is redirected to Log with log level INFO. This is just guessing but probably these are some of the reasons why the original snippet uses System.out.

You are free to replace the System.out.printf(...) calls with android.util.Log.i("sometag", String.format(...)) to get similar output in logcat.

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303