Why shouldn’t I use System.out.println() in android

You should use the android.util.Log class.

Here’s a description of what the Log class does:

API for sending log output.

Generally, you should use the Log.v(), Log.d(), Log.i(), Log.w(), and Log.e() methods to write logs. You can then view the logs in logcat.

The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.

These are the available methods of the Log class:

  1. Log.d() – Send a DEBUG log message.
  2. Log.e() – Send an ERROR log message.
  3. Log.i() – Send an INFO log message.
  4. Log.v() – Send a VERBOSE log message.
  5. Log.w() – Send a WARN log message.
  6. Log.wtf() – What a Terrible Failure: Report an exception that should never happen.

The methods above (with the exception of Log.w and Log.wtf which have 3 possible patterns of arguments) require the following arguments:

  1. String tag, String msg:

    tag: Used to identify the source of a log message. This value may be null.

    msg: The message you would like logged. This value may be null.

  2. String tag, String msg, Throwable tr – Similar to the first pattern, but allows for an exception to be specified. This pattern should be used if you want to log an exception to the log output.

  3. (For Log.w and Log.wtf) String tag, Throwable tr Similar to the third pattern, but does not allow for a message to be specified. Note that you can still pass a message but it should be in the second arrangement of arguments.


EDIT: Going straight to answer your question: println() of System.out and System.err will still be displayed in logcat but with limitations.

  • You can’t log VERBOSE, ERROR, or DEBUG using System.out or System.err.
  • You can’t define your own tag, it will display System.err or System.out with your text. For instance:

    • System.out.println("Hello!") is equivalent to Log.i("System.out","Hello!")
    • System.err.println("Hello!") is equivalent to Log.w("System.err","Hello!")

Leave a Comment