Android Logging and using Logcat

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • Log.v(String tag, String msg, Throwable tr)
  • Log.v(String tag, String msg)
  • Log.d(String tag, String msg, Throwable tr)
  • Log.d(String tag, String msg)
  • Log.i(String tag, String msg, Throwable tr)
  • Log.i(String tag, String msg)
  • Log.w(String tag, String msg, Throwable tr)
  • Log.w(String tag, String msg)
  • Log.e(String tag, String msg, Throwable tr)
  • Log.e(String tag, String msg)

Parameters

OptionDescription
-b (buffer)Loads an alternate log buffer for viewing, such as events or radio. The main buffer is used by default. See Viewing Alternative Log Buffers.
-cClears (flushes) the entire log and exits.
-dDumps the log to the screen and exits.
-f (filename)Writes log message output to (filename). The default is stdout.
-gPrints the size of the specified log buffer and exits.
-n (count)Sets the maximum number of rotated logs to (count). The default value is 4. Requires the -r option.
-r (kbytes)Rotates the log file every (kbytes) of output. The default value is 16. Requires the -f option.
-sSets the default filter spec to silent.
-v (format)Sets the output format for log messages. The default is brief format.

Remarks

Definition

Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class.

When to use

If you are considering using Java's System.out methods for printing to the console instead of using one of Android's Log methods, then you should know that they basically work the same. However, it is better to avoid using Java's methods because the extra information and formatting provided by Android's Log methods are more beneficial. Also, the System.out print methods are redirected to the Log.i() method.

Useful links



Got any Android Question?